コード例 #1
0
        public static async Task ExceptionToJSON(HttpContext context)
        {
            context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;

            var ex = context.Features.Get <IExceptionHandlerFeature>()?.Error;

            if (ex == null)
            {
                return;
            }
            var message = ex.Message;
            var detail  = ex.StackTrace;

            var error = new ProblemDetails(detail, message, 500);

            context.Response.ContentType = "application/json";

            using (var writer = new StreamWriter(context.Response.Body))
            {
                new JsonSerializer().Serialize(writer, error);
                await writer.FlushAsync().ConfigureAwait(false);
            }
        }
コード例 #2
0
 public WrappedResponse(ProblemDetails error)
 {
     this.Error = error;
 }