Class ExceptionHandlingConfig
Configures how AddExceptionHandler<TBuilder>(TBuilder) normalizes unexpected exceptions.
Implements
Inherited Members
Namespace: NanoRoute
Assembly: NanoRoute.dll
Syntax
public sealed record ExceptionHandlingConfig : IEquatable<ExceptionHandlingConfig>
Remarks
The configuration is stored in Metadata and follows normal builder scoping rules.
Examples
builder.ConfigureExceptionHandling(config => config with
{
ExceptionNormalizers = config.ExceptionNormalizers.SetItems
([
ExceptionNormalizer.For<InvalidOperationException>
(
static ex => new HttpRequestException("Conflict", ex, HttpStatusCode.Conflict)
)
])
});
Constructors
ExceptionHandlingConfig()
Declaration
public ExceptionHandlingConfig()
Properties
Default
Gets the default exception-handling configuration.
Declaration
public static ExceptionHandlingConfig Default { get; }
Property Value
| Type | Description |
|---|---|
| ExceptionHandlingConfig |
Remarks
The default configuration expands AggregateException into developer messages for its inner exceptions. Other unexpected exceptions are handled by the fallback internal-server-error normalizer in AddExceptionHandler<TBuilder>(TBuilder).
Examples
ExceptionHandlingConfig config = ExceptionHandlingConfig.Default;
ExceptionNormalizers
Gets the exception normalizers keyed by concrete exception type.
Declaration
public ImmutableDictionary<Type, ExceptionNormalizer> ExceptionNormalizers { get; init; }
Property Value
| Type | Description |
|---|---|
| ImmutableDictionary<Type, ExceptionNormalizer> |
Remarks
When a handler throws a non-HTTP, non-cancellation exception, AddExceptionHandler<TBuilder>(TBuilder) looks up the exception's exact runtime type in this dictionary. If no normalizer is registered, the exception is converted to a generic internal-server-error HttpRequestException.
Examples
builder.ConfigureExceptionHandling(config => config with
{
ExceptionNormalizers = config.ExceptionNormalizers.SetItems
([
ExceptionNormalizer.For<InvalidOperationException>
(
static ex => new HttpRequestException("Conflict", ex, HttpStatusCode.Conflict)
)
])
});
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when the assigned value is null. |