Base solution for your next web application
Open Closed

How to customize exception handling and error messages #1887


User avatar
0
pkouame created

Hi -

1 - working through the aspnetzero mpa core phonebook sample, I don't get the formatted error message in the guide. Rather I get this:

An unhandled exception occurred while processing the request.

AbpAuthorizationException: Required permissions are not granted. At least one of these permissions must be granted: Pages.Tenant.PhoneBook
MoveNext

Stack Query Cookies Headers
AbpAuthorizationException: Required permissions are not granted. At least one of these permissions must be granted: Pages.Tenant.PhoneBook
MoveNext
ThrowForNonSuccess

GetResult

...
...

MoveNext

Show raw exception details
Abp.Authorization.AbpAuthorizationException: Required permissions are not granted. At least one of these permissions must be granted: Pages.Tenant.PhoneBook
   at Abp.Authorization.PermissionCheckerExtensions.<AuthorizeAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Abp.Authorization.AuthorizationHelper.<AuthorizeAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

How do I configure my project to handle this exception correctly?

2 - How can I customize these error messages and pages?

Thanks in advance, Patrice


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    The error page you see is shown for development time. There is the below code in Startup.cs which does this.

    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseStatusCodePagesWithRedirects("~/Error?statusCode={0}");
        app.UseExceptionHandler("/Error");
    }
    

    If you want to see pretty error page on development time, you can chage it. If you want to modify the pretty error page, you can modify *.cshtml files under "Views\Error" folder.