27 lines
No EOL
864 B
C#
27 lines
No EOL
864 B
C#
using System.Net;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Diagnostics;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace RdtClient.Service.Middleware;
|
|
|
|
public static class ExceptionMiddlewareExtensions
|
|
{
|
|
public static void ConfigureExceptionHandler(this IApplicationBuilder app)
|
|
{
|
|
app.UseExceptionHandler(appError =>
|
|
{
|
|
appError.Run(async context =>
|
|
{
|
|
context.Response.StatusCode = (Int32) HttpStatusCode.InternalServerError;
|
|
context.Response.ContentType = "application/json";
|
|
|
|
var contextFeature = context.Features.Get<IExceptionHandlerFeature>();
|
|
if (contextFeature != null)
|
|
{
|
|
await context.Response.WriteAsync(contextFeature.Error.Message);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
} |