PHP Classes

File: backend/dotnet/Middleware/ExceptionHandlingMiddleware.cs

Recommend this page to a friend!
  Packages of Everton C B Junior   Igreja Aberta   backend/dotnet/Middleware/ExceptionHandlingMiddleware.cs   Download  
File: backend/dotnet/Middleware/ExceptionHandlingMiddleware.cs
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Igreja Aberta
Church activity management application
Author: By
Last change:
Date: 12 days ago
Size: 1,169 bytes
 

Contents

Class file image Download
using System.Net; using Jdb.Api.DTOs; namespace Jdb.Api.Middleware { public class ExceptionHandlingMiddleware { private readonly RequestDelegate _next; private readonly ILogger<ExceptionHandlingMiddleware> _logger; public ExceptionHandlingMiddleware(RequestDelegate next, ILogger<ExceptionHandlingMiddleware> logger) { _next = next; _logger = logger; } public async Task InvokeAsync(HttpContext context) { try { await _next(context); } catch (Exception exception) { _logger.LogError(exception, "Unhandled request error"); context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; context.Response.ContentType = "application/json"; await context.Response.WriteAsJsonAsync(new ApiResponse<object> { Code = StatusCodes.Status500InternalServerError, Data = null, Message = "Erro interno no servidor." }); } } } }