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.
- Host: GitHub
- URL: https://github.com/sixpaq/capitalsix.aspnetcore.middleware.errorhandling
- Owner: sixpaq
- Created: 2022-04-07T12:39:09.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-22T15:03:20.000Z (over 1 year ago)
- Last Synced: 2026-03-18T16:17:13.151Z (3 months ago)
- Topics: aspnetcore, errorhandling, json, middleware
- Language: C#
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
```