WsFederation Middleware Error Handling
The WsFederation Middleware by default will map unhandled Exceptions to HttpStatus codes depending on the type of Exception thrown. If more control over this error handling process is required, then the IWsFederationMiddlewareExceptionHandler
interface can be replaced to provide this functionality.
IWsFederationMiddlewareExceptionHandler
/// <summary>
/// Allows exceptions in the <see cref="IdentityServerWsFederationMiddleware"/> to be handled.
/// </summary>
public interface IWsFederationMiddlewareExceptionHandler
{
/// <summary>
/// Handle the exception
/// </summary>
/// <param name="context">HttpContext of the request</param>
/// <param name="wsFederationException">Exception thrown during the request</param>
/// <returns>
/// True if the exception was handled.
/// False if the exception should be handled by the middleware.
/// </returns>
bool Handle(HttpContext context, Exception wsFederationException);
}
The Handle
function exposes the HttpContext
and the Exception
that caused the failure. If the IWsFederationMiddlewareExceptionHandler
wants to handle the error, then the HttpContext
can be written to directly and a true
result returned. This will tell the middleware to halt any further processing or error handling.