Ouvert Fermé

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


User avatar
0
bozkan créé
  • 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 Réponse (s)
  • User Avatar
    0
    liangshiwei créé
    Équipe d'assistance Fullstack Developer

    Hi,

    Can you share your code? thanks.

  • User Avatar
    0
    bozkan créé

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

  • User Avatar
    0
    liangshiwei créé
    Équipe d'assistance 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 v8.2.0-preview Updated on mars 25, 2024, 15:11