Exemplo n.º 1
0
 private Task HandleExceptionsAsync(HttpContext context, Exception ex)
 {
     context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
     context.Response.ContentType = "application/json";
     try
     {
         ErrorType errorType = GenerateErrorHandler(ex);
         if (errorType.IsError())
         {
             context.Response.StatusCode = errorType.Get().StatusCode;
             _logger.Log(ex, errorType.Get().ResultCode);
             return(errorType.GenericResponse(context,
                                              ErrorDetailResponseFactory.CreateKnownErrorDetails(ex.Message, errorType.Get().ResultCode, errorType.Get().Title)));
         }
         _logger.Log(ex, errorType.Get().ResultCode);
         return(errorType.GenericResponse(context,
                                          ErrorDetailResponseFactory.CreateGenericErrorDetails(ex.Message, context.Response.StatusCode, ex)));
     }
     catch (Exception e)
     {
         _logger.Log(ex);
         return(HandleError.WithDefaultJsonConverter(context,
                                                     ErrorDetailResponseFactory.CreateGenericErrorDetails(e.Message, context.Response.StatusCode, e)));
     }
 }