Skip to content

Installation ​

Install AlmightyShogun.AspNet.Core in the ASP.NET Core application, or in a package that builds on it. The package targets net10.0 and references the ASP.NET Core shared framework. Every other package in this repository that returns an error response depends on it, so it is usually already present transitively.

sh
dotnet add package AlmightyShogun.AspNet.Core

Dependencies ​

Framework references ​

  • Microsoft.AspNetCore.App — the ASP.NET Core shared framework.

Package references ​

  • UAParser 3.1.47 — parses User-Agent headers for UserAgent.

Project references ​

  • AlmightyShogun.AspNet.Localization — resolves the localized description on every error body, so it arrives transitively and its Localization section applies here too.

Startup Registration ​

Each concern is registered on its own, so an application takes only what it needs. AddHttpErrorResponseWriter is the one everything else here depends on, and UseHttpErrorResponses adds the middleware that runs the handler chain and fills in empty error responses.

WARNING

Error bodies carry a localized description, so AddMessageLocalization is required alongside these calls. It lives in AlmightyShogun.AspNet.Localization and is not registered here.

csharp
using AlmightyShogun.AspNet.Core;
using AlmightyShogun.AspNet.Localization;

builder.Services
    .AddMessageLocalization(builder.Configuration)
    .AddHttpErrorResponseWriter()
    .AddExceptionHandling();

WebApplication app = builder.Build();

app.UseHttpErrorResponses();

All packages are released under the MIT License.