CrCore.Exceptions.AspNet
10.0.41
Prefix Reserved
See the version list below for details.
dotnet add package CrCore.Exceptions.AspNet --version 10.0.41
NuGet\Install-Package CrCore.Exceptions.AspNet -Version 10.0.41
<PackageReference Include="CrCore.Exceptions.AspNet" Version="10.0.41" />
<PackageVersion Include="CrCore.Exceptions.AspNet" Version="10.0.41" />
<PackageReference Include="CrCore.Exceptions.AspNet" />
paket add CrCore.Exceptions.AspNet --version 10.0.41
#r "nuget: CrCore.Exceptions.AspNet, 10.0.41"
#:package CrCore.Exceptions.AspNet@10.0.41
#addin nuget:?package=CrCore.Exceptions.AspNet&version=10.0.41
#tool nuget:?package=CrCore.Exceptions.AspNet&version=10.0.41
Intro
ASP.NET Core integration for CrCore.Exceptions.
This package provides automatic handling of CrException instances, converts them into RFC 7807 ProblemDetails responses, and supports configurable exception-to-HTTP status code and log level mappings.
Features
- ASP.NET Core exception handler
- RFC 7807
ProblemDetailsresponses - Configurable exception → HTTP status code mapping
- Configurable exception → log level mapping
- Generic handling of unexpected exceptions
Installation
dotnet add package CrCore.Exceptions.AspNet
Register the default exception handling during application startup.
builder.Services.AddCrExceptions();
app.UseExceptionHandler();
Default HTTP Status Code Mapping
| Exception | HTTP Status |
|---|---|
ValidationException |
400 |
UnauthorizedException |
401 |
ForbiddenException |
403 |
NotFoundException |
404 |
ConflictException |
409 |
UnprocessableException |
422 |
InternalException |
500 |
Custom HTTP Status Code Mapping
builder.Services.AddCrStatusCodeMapping(builder =>
{
builder.AddDefaultMappings();
builder.Map<MyCustomException>(StatusCodes.Status499ClientClosedRequest);
});
Default Log Level Mapping
| Exception | Log Level |
|---|---|
InternalException |
Error |
OtherUnregistered |
Debug |
Custom Log Level Mapping
builder.Services.AddCrLogLevelMapping(builder =>
{
builder.AddDefaultMappings();
builder.Map<MyCustomException>(LogLevel.Warning);
});
ProblemDetails Response
CrException instances are automatically converted into RFC 7807 ProblemDetails.
Example:
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.5",
"title": "Not Found",
"status": 404,
"detail": "The requested resource was not found.",
"instance": "/api/users/1",
"errors": [
{
"code": "Identity.UserNotFound",
"message": "User was not found."
}
],
"traceId": "..."
}
Clients should use errors[].code as the stable application error identifier.
Unexpected Exceptions
Exceptions that do not inherit from CrException are converted into a generic internal server error response.
Example:
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.6.1",
"title": "An error occurred while processing your request.",
"status": 500,
"detail": "An unexpected error occurred.",
"instance": "/api/users/1",
"errors": [
{
"code": "InternalError",
"message": "An unexpected internal error occurred."
}
],
"traceId": "..."
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- CrCore.Exceptions (>= 10.0.41)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.