namespace Kit.Helpers
{
    using System;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Mvc.Filters;

    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)]
    public class WebExceptionAttribute : ActionFilterAttribute, IExceptionFilter
    {
        public void OnException(ExceptionContext exceptionContext)
        {
            if (!exceptionContext.ExceptionHandled)
            {
                exceptionContext.ExceptionHandled = true;
                exceptionContext.HttpContext.Response.WriteException(exceptionContext.Exception);
                exceptionContext.Result = new EmptyResult();
            }
        }
    }
}