Delegate ExceptionNormalizer
Converts an unexpected exception into an enriched HttpRequestException.
Namespace: NanoRoute
Assembly: NanoRoute.dll
Syntax
public delegate HttpRequestException ExceptionNormalizer(Exception exception)
Parameters
| Type | Name | Description |
|---|---|---|
| Exception | exception | The exception thrown by a later handler in the routing pipeline. |
Returns
| Type | Description |
|---|---|
| HttpRequestException | The HttpRequestException that should be thrown by the exception-handling middleware. |
Remarks
Normalizers are configured with ConfigureExceptionHandling<TBuilder>(TBuilder, ConfigureBuilderDelegate<ExceptionHandlingConfig>). They run only for exception types registered in ExceptionNormalizers. Existing HttpRequestException and OperationCanceledException values are not normalized by AddExceptionHandler<TBuilder>(TBuilder). Exceptions thrown by a normalizer propagate from the exception-handling middleware.
Examples
builder.ConfigureExceptionHandling(config => config with
{
ExceptionNormalizers = config.ExceptionNormalizers.SetItems
([
ExceptionNormalizer.For<InvalidOperationException>
(
static ex => new HttpRequestException("Bad state", ex, HttpStatusCode.Conflict)
)
])
});