Starts in:
2 DAYS
7 HRS
8 MIN
30 SEC
Starts in:
2 D
7 H
8 M
30 S
Open Closed

ASP.NET Core UseExceptionHandler extension do not work with ABP #1821


User avatar
0
bozkan created
  • ABP Framework version: v4.3.0
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:" Apply method explained on https://docs.microsoft.com/en-us/aspnet/core/fundamentals/error-handling?view=aspnetcore-5.0#exception-handler-lambda

I am trying to globally catch (and modify) any exceptions occured on my ABP project and trying different methods which no one could be successful so far. One of them is using the exception handler lambda explained on https://docs.microsoft.com/en-us/aspnet/core/fundamentals/error-handling?view=aspnetcore-5.0#exception-handler-lambda. Even if I configured the lambda and throw exception in some method, the lambda method is not hit.


3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Can you share your code? thanks.

  • User Avatar
    0
    bozkan created

    It's just a simple app service method that I throw exception on purpose.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    It works for me.

    public class IndexModel : AbpPageModel
    {
        public void OnGet()
        {
            throw new Exception("test");
        }
    }
    
    app.UseExceptionHandler(x => x.Run(async errorContext =>
    {
        errorContext.Response.StatusCode = (int) HttpStatusCode.InternalServerError;
        errorContext.Response.ContentType = "text/html";
    
        await errorContext.Response.WriteAsync("<html lang=\"en\"><body>\r\n");
        await errorContext.Response.WriteAsync("ERROR!<br><br>\r\n");
    
        var exceptionHandlerPathFeature =
            errorContext.Features.Get<IExceptionHandlerPathFeature>();
    
        if (exceptionHandlerPathFeature?.Error is FileNotFoundException)
        {
            await errorContext.Response.WriteAsync(
                "File error thrown!<br><br>\r\n");
        }
    
        await errorContext.Response.WriteAsync(
            "<a href=\"/\">Home</a><br>\r\n");
        await errorContext.Response.WriteAsync("</body></html>\r\n");
        await errorContext.Response.WriteAsync(new string(' ', 512));
    }));
    

    Could you share a project to reproduce it? shiwei.liang@volosoft.com

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06