rdt-client/server/RdtClient.Service/Middleware/ExceptionMiddlewareExtensions.cs
Roger Far cd6002b5d6 Upgrade packages
Moved C# code to file scoped namespaces
Merged Startup.cs and Program.cs
2022-04-30 11:22:15 -06:00

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);
}
});
});
}
}