Ejemplo n.º 1
0
 private static async Task WriteResponse(HttpContext context, ExceptionResponse exceptionResponse, ApiResponse problemDetails)
 {
     context.Response.StatusCode  = StatusCodes.Status500InternalServerError;
     context.Response.ContentType = "application/json";
     await context.Response
     .WriteAsync(exceptionResponse == null
                 ?problemDetails.ToString()
                     : exceptionResponse.ResponseText).ConfigureAwait(false);
 }
Ejemplo n.º 2
0
        private async Task HandleExceptionAsync(HttpContext context, Exception exception)
        {
            ExceptionResponse exceptionResponse = default;

            _logger.LogCritical(exception, nameof(ExceptionMiddleware));
            var error    = new ErrorMessage <ErrorType>(ErrorType.ServerError, exception);
            var response = new ApiResponse {
                Success = false, Error = error
            };

            await WriteResponse(context, exceptionResponse, response);
        }