0

I wanna return the details of exception with ABP .NET Core, what I noticed is when I go to AbpAuditLogs table and App_Data\Logs logFile they contain the exception in details but when I use below method to return the exception it shows only general exception without any details (500 Internal Server Error)

try{
:
:
:
}
catch (Exception ex)
{
                throw new System.ArgumentException(ex.InnerException.Message.ToString(), "original");
}

So, How could I return the specific Exception for the user for Example Email Validation Exception and so on?

Update:

I will explain more to make the question more clear :

The way that I handled the exception is attached with this question above . The problem is when hitting a request on the service from swagger or Postman always see General Error with status Code 500 without any details and that force me to review the details of the exception from Log File or Log Table , I wanna see the details of the exception (e.g FileNotFoundException ) directly from Swagger or Postman without return back to Log File or AbpAuditLogs Table.

Abdulaziz
  • 654
  • 3
  • 12
  • 37
  • Does this answer your question? [How to get more detailed exception in ABP?](https://stackoverflow.com/questions/48050689/how-to-get-more-detailed-exception-in-abp) – aaron Sep 06 '20 at 08:45

3 Answers3

4

I think User Friendly Exception will work for you.

Because if an exception implements the IUserFriendlyException interface, then ABP does not change it's Message and Details properties and directly send it to the client.

throw new UserFriendlyException(
"Username should be unique!"
);

You can find more information here.

berkansasmaz
  • 608
  • 5
  • 16
  • but that mean should I write each exception manually I couldn't get it from returned exception Object (e.g ex.InnerException.Message) – Abdulaziz Sep 02 '20 at 07:37
  • I don't know if I fully understood your question, but it works for me based on my own experiments. I did as in the sample code block in your question. After I caught an exception, I throw a different exception. This exception I throw is UserFriendlyException. If ex.InnerException.Message is not null, it should work as expected. – berkansasmaz Sep 02 '20 at 08:04
  • for the ABP template front -end it returned the details but in swagger or any other HTTP client it only shows Error: Internal Server Error – Abdulaziz Sep 03 '20 at 03:39
  • I tested what you said. I saw the same error message on the clients I tested. If you still have the same problem, can you explain your example in more detail? Before you start, you can look at [this](https://github.com/abpframework/abp/issues/3471) topic, it may solve your problem. – berkansasmaz Sep 03 '20 at 07:08
  • thank you I've updated my question and I found the answer, anyway thank you for your help. – Abdulaziz Sep 04 '20 at 02:00
1

Actually, I found the answer in this question for @Mehdi Daustany .what I did is exactly what @Mehdi Daustany answered, I've added below code :

   if (_env.EnvironmentName.ToLower() == "development")
    Configuration.Modules.AbpWebCommon().SendAllExceptionsToClients = true;

under ***.Web.Core then the details of exception appeared in the Swagger

Abdulaziz
  • 654
  • 3
  • 12
  • 37
0
services.Configure<AbpExceptionHandlingOptions>  (options =>
{
    options.SendExceptionsDetailsToClients = true;
});

Above code will configure abp to return all the exception details. Just add it to the configuration.

Harun Diluka Heshan
  • 1,155
  • 2
  • 18
  • 30