Exemplo n.º 1
0
        private Task HandleExceptionAsync(HttpContext context)
        {
            var error = new InternalErrorResponse();

            context.Response.ContentType = "application/json";
            context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;

            var serializeOptions = new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                WriteIndented        = true
            };

            var result = JsonSerializer.Serialize(error, serializeOptions);

            return(context.Response.WriteAsync(result));
        }
Exemplo n.º 2
0
        private static Task HandleExceptionAsync(HttpContext context, Exception exception)
        {
            context.Response.ContentType = "application/json";

            var error = new InternalErrorResponse(new Error
            {
                // TODO: In production should be this code line ↓
                // Code = ErrorCodes.System.InternalError,
                // TODO: In production this code line should be removed ↓
                Code    = exception.StackTrace,
                Message = exception.Message,
            });

            var result = JsonConvert.SerializeObject(error);

            context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;

            return(context.Response.WriteAsync(result));
        }