| 123456789101112131415161718192021222324252627282930 |
- using Microsoft.AspNetCore.Diagnostics;
- using System.Net;
-
- namespace BlackRock.Reporting.API.Exceptions
- {
- public static class ExceptionMiddlewareExtensions
- {
- public static void ConfigureExceptionHandler(this IApplicationBuilder app, ILoggingBuilder logger)
- {
- app.UseExceptionHandler(appError =>
- {
- appError.Run(async context =>
- {
- context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
- context.Response.ContentType = "application/json";
- var contextFeature = context.Features.Get<IExceptionHandlerFeature>();
- if (contextFeature != null)
- {
- //logger.LogError($"Something went wrong: {contextFeature.Error}");
- await context.Response.WriteAsync(new Error()
- {
- StatusCode = (HttpStatusCode)context.Response.StatusCode,
- Title = "Internal Server Error from Custom MiidleWare"
- }.ToString());
- }
- });
- });
- }
- }
- }
|