CrCore.Exceptions.AspNet
10.0.45
Prefix Reserved
dotnet add package CrCore.Exceptions.AspNet --version 10.0.45
NuGet\Install-Package CrCore.Exceptions.AspNet -Version 10.0.45
<PackageReference Include="CrCore.Exceptions.AspNet" Version="10.0.45" />
<PackageVersion Include="CrCore.Exceptions.AspNet" Version="10.0.45" />
<PackageReference Include="CrCore.Exceptions.AspNet" />
paket add CrCore.Exceptions.AspNet --version 10.0.45
#r "nuget: CrCore.Exceptions.AspNet, 10.0.45"
#:package CrCore.Exceptions.AspNet@10.0.45
#addin nuget:?package=CrCore.Exceptions.AspNet&version=10.0.45
#tool nuget:?package=CrCore.Exceptions.AspNet&version=10.0.45
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
builder.Services.AddCrExceptionsCore();
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 |
|---|---|
ValidationException |
Debug |
UnauthorizedException |
Debug |
ForbiddenException |
Debug |
NotFoundException |
Debug |
ConflictException |
Debug |
UnprocessableException |
Debug |
InternalException |
Error |
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,
"errors": [
{
"code": "TestNotFoundCode",
"message": "Test not found message"
}
],
"traceId": "c771b28502648371f14885924e6d1767"
}
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,
"errors": [
{
"code": "InternalError",
"message": "An unexpected internal error occurred."
}
],
"traceId": "9bf8d72774b6f2d97cac7607bb19f408"
}
| 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.45)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.