Centralized API Exception handler
CAPIEH is a package to centralize all the exception handling and create a unified response format.
It's build around a middleware that places a big try catch on your pipeline. If an error is caught, it will invoke your delegated ExceptionHandler to handle your exception the way you want.
It gives the benifit to add translations to your message, make use of error codes, set error types, set exception identifiers to track in your logging, and more ...
The main package on nuget.org:
PM> Install-Package CAPIEH.Core
The abstractions containing apiResponse wrapping models:
Coming Soon
Registering the dependencies in an ASP.NET Core application, using Microsoft.Extensions.DependencyInjection, is pretty simple:
You propagate how how exceptions should be handled and / or returned as a response, by creating and pluging your own ExceptionHandler Delegate. You set this up as followed:
// EXAMPLE
A generic response message will look like this
{
"data": {
... Your data model
},
"error": {
"id": "Identifier to track inside the logging",
"message": "A generic or custom message",
"type": "exception types (application exception, validation exception, ... whatever you can make up)",
"code": "an exception code that can be used on the client to set/translate exception messages client side",
"info": object (optional object to add custom data to your client),
},
"status": "string",
"statusCode": 100 // HttpStatusCode
}