forked from AcaMate/AcaMate_API
50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
using System.Text.Json;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.Logging;
|
|
using System.Threading.Tasks;
|
|
using Back.Program.Common.Model;
|
|
|
|
namespace Back.Program.Common.Middleware
|
|
{
|
|
public class ExceptionMiddleware
|
|
{
|
|
private readonly RequestDelegate _next;
|
|
private readonly ILogger<ExceptionMiddleware> _logger;
|
|
|
|
public ExceptionMiddleware(RequestDelegate next, ILogger<ExceptionMiddleware> logger)
|
|
{
|
|
_next = next;
|
|
_logger = logger;
|
|
}
|
|
|
|
// public async Task Invoke(HttpContext context)
|
|
// {
|
|
// try
|
|
// {
|
|
// await _next(context); // 다음 미들웨어 호출
|
|
// }
|
|
// catch (AcaException ex)
|
|
// {
|
|
// _logger.LogWarning(ex, "AcaException 발생");
|
|
// context.Response.StatusCode = 400;
|
|
//
|
|
// var response = APIResponse.Send<string>(ex.Code, ex.Message, "");
|
|
// var json = JsonSerializer.Serialize(response);
|
|
//
|
|
// context.Response.ContentType = "application/json; charset=utf-8";
|
|
// await context.Response.WriteAsync(json);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Unhandled Exception");
|
|
// context.Response.StatusCode = 500;
|
|
//
|
|
// var response = APIResponse.InternalSeverError("서버 내부 오류가 발생했습니다.");
|
|
// var json = JsonSerializer.Serialize(response);
|
|
//
|
|
// context.Response.ContentType = "application/json; charset=utf-8";
|
|
// await context.Response.WriteAsync(json);
|
|
// }
|
|
// }
|
|
}
|
|
} |