Created
April 21, 2021 08:56
-
-
Save Regenhardt/08831aeee4136e47d4351b7ca89ff29a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExceptionHandler : IMiddleware | |
{ | |
public async Task InvokeAsync(HttpContext context, RequestDelegate next) | |
{ | |
try | |
{ | |
await next(context); | |
} | |
catch (Exception e) | |
{ | |
var result = JsonSerializer.Serialize(Result.Negative(e.ToString())); | |
context.Response.StatusCode = StatusCodes.Status200OK; | |
context.Response.ContentType = "application/json"; | |
await context.Response.WriteAsync(result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment