21 lines
822 B
C#
21 lines
822 B
C#
using System;
|
|
using System.Net;
|
|
using EstusShots.Shared.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Filters;
|
|
|
|
namespace EstusShots.Server.Filters
|
|
{
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
|
|
public class CustomExceptionFilterAttribute : ExceptionFilterAttribute
|
|
{
|
|
public override void OnException(ExceptionContext context)
|
|
{
|
|
var code = HttpStatusCode.InternalServerError;
|
|
context.HttpContext.Response.ContentType = "application/json";
|
|
context.HttpContext.Response.StatusCode = (int)code;
|
|
var response = new ApiResponse<CriticalErrorResponse>(new OperationResult(false, "Critical Server Error", context.Exception.Message));
|
|
context.Result = new JsonResult(response);
|
|
}
|
|
}
|
|
} |