public static void HandleUnauthorizedExceptions( this ExceptionHandlerConfiguration configuration, IWebHostEnvironment hostingEnvironment) { configuration.Map <UnauthorizedAccessException>() .ToStatusCode(StatusCodes.Status401Unauthorized) .WithBody((ex, context) => FormatErrorResponse(hostingEnvironment, context, ex, ErrorMessages.Unauthorized)); }
public static void HandleHttpValidationExceptions( this ExceptionHandlerConfiguration configuration, IWebHostEnvironment hostingEnvironment) { configuration.Map <ValidationException>() .ToStatusCode(StatusCodes.Status400BadRequest) .WithBody((ex, context) => FormatErrorResponse(hostingEnvironment, context, ex, ex.Message)); }
public static void HandleOperationCancelledExceptions( this ExceptionHandlerConfiguration configuration, IWebHostEnvironment hostingEnvironment) { configuration.Map <OperationCanceledException>() .ToStatusCode(499) .WithBody((ex, context) => FormatErrorResponse(hostingEnvironment, context, ex, ErrorMessages.OperationCancelled)); }
public static ExceptionHandlerOptions SetHandler(this ExceptionHandlerOptions exceptionHandlerOptions, Action<ExceptionHandlerConfiguration> configurationAction) { var configuration = new ExceptionHandlerConfiguration(ExceptionConfig.UnsafeFormatterWithDetails); configurationAction(configuration); exceptionHandlerOptions.ExceptionHandler = configuration.BuildHandler(); return exceptionHandlerOptions; }
public static void HandleUnhandledExceptions( this ExceptionHandlerConfiguration configuration, IWebHostEnvironment hostingEnvironment) { configuration.ContentType = "application/problem+json"; configuration.Map <Exception>() .ToStatusCode(StatusCodes.Status500InternalServerError) .WithBody((ex, context) => FormatErrorResponse(hostingEnvironment, context, ex, ErrorMessages.InternalServer)); }