AugusteVN.Api.Exceptions
1.0.5
dotnet add package AugusteVN.Api.Exceptions --version 1.0.5
NuGet\Install-Package AugusteVN.Api.Exceptions -Version 1.0.5
<PackageReference Include="AugusteVN.Api.Exceptions" Version="1.0.5" />
<PackageVersion Include="AugusteVN.Api.Exceptions" Version="1.0.5" />
<PackageReference Include="AugusteVN.Api.Exceptions" />
paket add AugusteVN.Api.Exceptions --version 1.0.5
#r "nuget: AugusteVN.Api.Exceptions, 1.0.5"
#:package AugusteVN.Api.Exceptions@1.0.5
#addin nuget:?package=AugusteVN.Api.Exceptions&version=1.0.5
#tool nuget:?package=AugusteVN.Api.Exceptions&version=1.0.5
Exceptions
Handle exceptions in server-side (HTTP) context.
Includes: GlobalExceptionHandler implementing the IExceptionHandler interface.
This will handle the following exception types out-of-the-box:
ValidationException(FluentValidation)ForbiddenAccessException(AugusteVN.Features.Exceptions)NotFoundException(AugusteVN.Features.Exceptions)UnauthorizedAccessException_ => HandleUnknownException
Or, you can use your own class by having it implement ICustomExceptionHandler.
Register Class Only
Default CustomExceptionHandler registration as scoped and implements ICustomExceptionHandler.
Use case: access the default Exception handling logic in your own middleware or filters. Used by: https://www.nuget.org/packages/AugusteVN.Api.EndpointFilters/
builder.Services.AddCustomExceptionHandler();
Usage Example
public class EndpointExceptionFilter (ICustomExceptionHandler exceptionHandler) : IEndpointFilter
{
public async ValueTask<object?> InvokeAsync(EndpointFilterInvocationContext context, EndpointFilterDelegate next)
{
try
{
return await next(context);
}
catch (Exception e)
{
return exceptionHandler.Handle(e);
}
}
}
Register as Global Exception Handler
Registers the implementation class for ICustomExceptionHandler and as global handler a GlobalExceptionHandler for IExceptionHandler.
By default GlobalExceptionHandler will use CustomExceptionHandler but you can use your own implementation for ICustomExceptionHandler.
This includes the registration of requirement: .AddProblemDetails().
builder.Services.AddGlobalExceptionHandler();
// Or, with your handler class.
builder.Services.AddGlobalExceptionHandler<TCustomHandler>();
...
app.UseExceptionHandler();
Register as Middleware
An alternative approach, not using the IExceptionHandler is to simply register it as middleware.
builder.Services.AddGlobalExceptionHandlingMiddleware();
// Or, with your handler class.
builder.Services.AddGlobalExceptionHandlingMiddleware<TCustomHandler>();
...
app.UseMiddleware<GlobalExceptionHandlerMiddleware>();
Get the original source code: kiss-code.com
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- AugusteVN.Features.Exceptions (>= 1.0.0)
- FluentValidation.DependencyInjectionExtensions (>= 11.8.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AugusteVN.Api.Exceptions:
| Package | Downloads |
|---|---|
|
AugusteVN.Api.EndpointFilters
A collection of endpoint filters for a minimal API. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Return ProblemDetails instead of IResult.