Custom Headers Test 4 (#2524)

This commit is contained in:
Joe Milazzo 2024-01-05 14:56:46 -06:00 committed by GitHub
parent d85208513f
commit 3765ad929a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 129 additions and 52 deletions

View file

@ -9,27 +9,17 @@ using Microsoft.Extensions.Logging;
namespace API.Middleware;
public class ExceptionMiddleware
public class ExceptionMiddleware(RequestDelegate next, ILogger<ExceptionMiddleware> logger)
{
private readonly RequestDelegate _next;
private readonly ILogger<ExceptionMiddleware> _logger;
public ExceptionMiddleware(RequestDelegate next, ILogger<ExceptionMiddleware> logger)
{
_next = next;
_logger = logger;
}
public async Task InvokeAsync(HttpContext context)
{
try
{
await _next(context); // downstream middlewares or http call
await next(context); // downstream middlewares or http call
}
catch (Exception ex)
{
_logger.LogError(ex, "There was an exception");
logger.LogError(ex, "There was an exception");
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int) HttpStatusCode.InternalServerError;