27 lines
762 B
C#
27 lines
762 B
C#
using System.Text.Json;
|
|
using Integry_Smart_Warehouse.Core.WebHost.Dto;
|
|
using Microsoft.AspNetCore.Diagnostics;
|
|
|
|
namespace Integry_Smart_Warehouse.Core.WebHost.Controller;
|
|
|
|
public class ResponseBaseExceptionWrapper
|
|
{
|
|
public async Task Invoke(HttpContext context)
|
|
{
|
|
var contextFeature = context.Features.Get<IExceptionHandlerFeature>();
|
|
if (contextFeature is { Error: { } })
|
|
{
|
|
context.Response.StatusCode = StatusCodes.Status200OK;
|
|
context.Response.ContentType = "application/json";
|
|
|
|
await context.Response.WriteAsync(JsonSerializer.Serialize(new ResponseBaseDto()
|
|
{
|
|
Esito = -1,
|
|
ErrorMessage = contextFeature.Error.Message
|
|
}, new JsonSerializerOptions()
|
|
{
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
|
}));
|
|
}
|
|
}
|
|
} |