An open API service indexing awesome lists of open source software.

https://github.com/sixpaq/capitalsix.aspnetcore.middleware.errorhandling

Middleware module for aspnetcore, which handles all uncaught exceptions and creates customizable JSON responses.
https://github.com/sixpaq/capitalsix.aspnetcore.middleware.errorhandling

aspnetcore errorhandling json middleware

Last synced: about 2 months ago
JSON representation

Middleware module for aspnetcore, which handles all uncaught exceptions and creates customizable JSON responses.

Awesome Lists containing this project

README

          

# CapitalSix.AspNetCore.Middleware.ErrorHandling

This module captures "uncaught" exceptions and generated ProblemDetail results in json format.

### How to configure the module.
```c#
void ConfigureServices(IServicesCollection services)
{
...
services
.AddControllers()
.AddExceptionMiddleware();
...
}

void Configure(IApplicationBuilder app)
{
...
app.UseExceptionMiddleware();
...
}
```

### Customizing
It is possible to customize the middleware by adding custom mappings. For each type of
exception a mapping can be added. This mapping is responsible for the conversion
from Exception to ProblemDetails.
```c#
void ConfigureServices(IServicesCollection services)
{
...
services.Configure(options =>
{
options.Mappings.Add(ex =>
new ProblemDetails()
{
Status = 500,
Title = "Arguments are not allowed to be null"
});
});
...
}
builder.Services
```