Class StrataraProblemDetailsExceptionHandler
- Namespace
- Stratara.ServiceDefaults.AspNetCore
- Assembly
- Stratara.ServiceDefaults.AspNetCore.dll
Maps the framework's own failure types to an RFC 7807 problem response, so a caller receives one shape for every framework rejection instead of one shape per failure type.
public sealed class StrataraProblemDetailsExceptionHandler : IExceptionHandler
- Inheritance
-
StrataraProblemDetailsExceptionHandler
- Implements
- Inherited Members
- Extension Methods
Remarks
Handles exactly four types: a validation rejection becomes 400 carrying the failures
grouped by the field each concerns; an authorization refusal and a tenant-access denial each
become 403. Everything else is left alone and propagates unchanged — a host with its own
error model keeps it, and a bug in a handler still reaches the host's own diagnostics rather than
being flattened into a tidy 500.
A caller that is not authenticated is answered 401 instead, for an authorization refusal,
a tenant-access denial and a SessionRequiredException alike: what such a caller lacks
is an identity, not a permission. Where the host has a default challenge scheme the handler
challenges through it — so a bearer client receives WWW-Authenticate and a cookie client is
redirected, as [Authorize] would do — and writes the problem body only when the challenge
leaves an unstarted 401. Without a scheme it writes a 401 problem response itself.
A SessionRequiredException for an authenticated caller is not converted: it means
the host did not establish the session context, and that stays loud.
Registered by AddStrataraProblemDetails(); a host that does not call it converts nothing.
Methods
TryHandleAsync(HttpContext, Exception, CancellationToken)
Tries to handle the specified exception asynchronously within the ASP.NET Core pipeline. Implementations of this method can provide custom exception-handling logic for different scenarios.
public ValueTask<bool> TryHandleAsync(HttpContext httpContext, Exception exception, CancellationToken cancellationToken)
Parameters
httpContextHttpContextThe HttpContext for the request.
exceptionExceptionThe unhandled exception.
cancellationTokenCancellationTokenThe cancellation token.