-
ABP Framework version: v8.0.2
-
UI Type: Angular
-
Database System: EF Core (SQL Server)
-
Tiered (for MVC) or Auth Server Separated (for Angular): yes
How can I set an error code and override the default generic error message ("An internal error occurred during your request!") for the unexpected exceptions?
{
"error": {
"code": null,
"message": "An internal error occurred during your request!",
"details": null,
"data": {},
"validationErrors": null
}
}
4 Answer(s)
-
0
Hi, ABP provides an Error Handling System, which allow you to customize error message and the relevant HTTP status code. Please check the Exception Handling documentation. In the documentation, you can see how to set custom HTTP status code for certain exception and how to customize error message etc.
For the exception that you shared, it's not handled by ABP it seems, so we need further info about the exception, where it's thrown, the related endpoint etc.
Best regards.
-
0
Hi @EngincanV, I understand that I can wrap each endpoint in a try-catch block to handle unexpected errors, but that would be time-consuming for us. Is there a way to centrally handle unexpected errors and return a specific error code and message?
-
0
Hi @EngincanV, I understand that I can wrap each endpoint in a try-catch block to handle unexpected errors, but that would be time-consuming for us. Is there a way to centrally handle unexpected errors and return a specific error code and message?
ABP already has a built-in mechanism for global exception handling so you don’t have to wrap each endpoint in a try-catch block. ABP automatically handles all exceptions and sends a standard formatted error message to the client for an API/AJAX request.
But in your case, since it does not met the exception handling criteria it's not handled by ABP. So, you can subscribe to all of the thrown exceptions by implementing the
ExceptionSubscriber
base class, as described here. You can apply your own logic for the thrown exceptions. -
0
Hi @EngincanV,
noted, I will explore the ExceptionSubcriber. Thank you!