Adding exception handler
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Diagnostics;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
@@ -54,6 +56,17 @@ namespace WD7UVN_HFT_2023241.Endpoint
|
|||||||
{
|
{
|
||||||
endpoints.MapControllers();
|
endpoints.MapControllers();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.UseExceptionHandler(c => c.Run(async context =>
|
||||||
|
{
|
||||||
|
var exception = context.Features
|
||||||
|
.Get<IExceptionHandlerPathFeature>()
|
||||||
|
.Error;
|
||||||
|
|
||||||
|
var response = new { Msg = exception.Message };
|
||||||
|
|
||||||
|
await context.Response.WriteAsJsonAsync(response);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user