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.
dotnet add package AlmightyShogun.AspNet.CoreDependencies
Framework references
Microsoft.AspNetCore.App— the ASP.NET Core shared framework.
Package references
UAParser3.1.47— parses User-Agent headers forUserAgent.
Project references
AlmightyShogun.AspNet.Localization— resolves the localized description on every error body, so it arrives transitively and itsLocalizationsection 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.
using AlmightyShogun.AspNet.Core;
using AlmightyShogun.AspNet.Localization;
builder.Services
.AddMessageLocalization(builder.Configuration)
.AddHttpErrorResponseWriter()
.AddExceptionHandling();
WebApplication app = builder.Build();
app.UseHttpErrorResponses();