Esempio n. 1
0
 public static void HandleUnauthorizedExceptions(
     this ExceptionHandlerConfiguration configuration,
     IWebHostEnvironment hostingEnvironment)
 {
     configuration.Map <UnauthorizedAccessException>()
     .ToStatusCode(StatusCodes.Status401Unauthorized)
     .WithBody((ex, context) => FormatErrorResponse(hostingEnvironment, context, ex, ErrorMessages.Unauthorized));
 }
Esempio n. 2
0
 public static void HandleHttpValidationExceptions(
     this ExceptionHandlerConfiguration configuration,
     IWebHostEnvironment hostingEnvironment)
 {
     configuration.Map <ValidationException>()
     .ToStatusCode(StatusCodes.Status400BadRequest)
     .WithBody((ex, context) => FormatErrorResponse(hostingEnvironment, context, ex, ex.Message));
 }
Esempio n. 3
0
 public static void HandleOperationCancelledExceptions(
     this ExceptionHandlerConfiguration configuration,
     IWebHostEnvironment hostingEnvironment)
 {
     configuration.Map <OperationCanceledException>()
     .ToStatusCode(499)
     .WithBody((ex, context) => FormatErrorResponse(hostingEnvironment, context, ex, ErrorMessages.OperationCancelled));
 }
Esempio n. 4
0
        public static ExceptionHandlerOptions SetHandler(this ExceptionHandlerOptions exceptionHandlerOptions, Action<ExceptionHandlerConfiguration> configurationAction)
        {
            var configuration = new ExceptionHandlerConfiguration(ExceptionConfig.UnsafeFormatterWithDetails);
            configurationAction(configuration);

            exceptionHandlerOptions.ExceptionHandler = configuration.BuildHandler();
			return exceptionHandlerOptions;
        }
Esempio n. 5
0
 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));
 }