Base solution for your next web application
Open Closed

Showing meaningful messages instead of Internal Server Error. #6523


User avatar
0
hsudas created

Instead of "Internal Server Error" we would like to show meaningful Exception messages on the client. For example If any error occurs in a service method. We just want to show that messages via a pop-up on our Angular (v6) web client. But every messages coming to UI with a standart "An internal error occured during your request" and with 500 status code. Looking forward your help.

Regards.


4 Answer(s)
  • User Avatar
    1
    aaron created
    Support Team

    Throw UserFriendlyException.

    https://aspnetboilerplate.com/Pages/Documents/Handling-Exceptions#showing-exceptions

  • User Avatar
    0
    hsudas created

    Thanks for the answer. If we throw the specific exception with UserFriendlyException it is appearing on the UI. But I would like to implement this behaviour for all exceptions are coming from aspnet-core server application. In which code block should implement this solution to catch and convert them to user friendly exceptions ?

  • User Avatar
    0
    aaron created
    Support Team

    You can set SendAllExceptionsToClients = true.

    https://aspnetboilerplate.com/Pages/Documents/Startup-Configuration#configuring-modules

  • User Avatar
    0
    maliming created
    Support Team

    @hsudas

    Some exceptions should not be shown to the user. For example: database errors, exceptions that occur in the helper component, etc.

    You can control exceptions, preferably using UserFriendlyException.