Skip to content

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

Notifications You must be signed in to change notification settings

sixpaq/CapitalSix.AspNetCore.Middleware.ErrorHandling

Repository files navigation

CapitalSix.AspNetCore.Middleware.ErrorHandling

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

How to configure the module.

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.

void ConfigureServices(IServicesCollection services)
{
    ...
    services.Configure<ExceptionMiddlewareOptions>(options =>
    {
        options.Mappings.Add<ArgumentNullException>(ex =>
             new ProblemDetails()
            {
                Status = 500,
                Title = "Arguments are not allowed to be null"
            });
    });
    ...
}
builder.Services

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages