Church.Net.API/WebAPI/HandleExceptionFilter.cs
2022-09-08 08:04:32 -07:00

43 lines
1.4 KiB
C#

using System.Threading.Tasks;
using System.Threading;
using System.Web.Http.Filters;
using System;
using WebAPI.Services.Interfaces;
namespace WebAPI
{
public class HandleExceptionFilter : IExceptionFilter
{
private ILoggingService _loggingService;
public HandleExceptionFilter(ILoggingService loggingService)
{
_loggingService = loggingService;
}
public bool AllowMultiple => throw new NotImplementedException();
public Task ExecuteExceptionFilterAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)
{
return Task.Run(new Action(() =>
{
if (actionExecutedContext == null)
{
throw new ArgumentNullException("filterContext");
}
Exception exception = actionExecutedContext.Exception;
if (actionExecutedContext.Response.StatusCode == System.Net.HttpStatusCode.InternalServerError)
{
// Log exception
//_loggingService.Error(exception);
int errorTrackNo = _loggingService.Error(exception, actionExecutedContext.Request.RequestUri.AbsoluteUri);
//actionExecutedContext.Exception = new HttpException($"Error Track No:{errorTrackNo}");
}
}));
}
}
}