File size: 650 Bytes
8edbc20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using Backend_Teamwork.src.Utils;

namespace Backend_Teamwork.src.Middleware
{
    public class ErrorHandlerMiddleware
    {
        private readonly RequestDelegate _next;
        public ErrorHandlerMiddleware(RequestDelegate next){
            _next = next;
        }
        public async Task InvokeAsync(HttpContext context){
            try{
                await _next(context);
            }catch(CustomException ex){
                context.Response.StatusCode = ex.StatusCode;
                context.Response.ContentType = "application/json";
                await context.Response.WriteAsync(ex.Message);
            }   
        }
    }
}