diff --git a/Falcon.SugarApi/ApiDefinistions/HttpResponseExceptionFilter.cs b/Falcon.SugarApi/ApiDefinistions/HttpResponseExceptionFilter.cs index 5dbf0d0..63c6656 100644 --- a/Falcon.SugarApi/ApiDefinistions/HttpResponseExceptionFilter.cs +++ b/Falcon.SugarApi/ApiDefinistions/HttpResponseExceptionFilter.cs @@ -6,6 +6,9 @@ using System.Text; namespace Falcon.SugarApi.ApiDefinistions { + /// + /// 异常处理筛选器 + /// public class HttpResponseExceptionFilter : IActionFilter, IOrderedFilter { /// @@ -13,32 +16,36 @@ namespace Falcon.SugarApi.ApiDefinistions /// public ILogger Logger { get; set; } - public HttpResponseExceptionFilter(ILogger logger) - { + /// + /// api异常状态码 + /// + public int StatusCode { get; set; } = 400; + + /// + public HttpResponseExceptionFilter(ILogger logger) { this.Logger = logger; } + /// public int Order { get; } = int.MaxValue - 10; + /// public void OnActionExecuting(ActionExecutingContext context) { } - public void OnActionExecuted(ActionExecutedContext context) - { - if (context.Exception == null || context.ExceptionHandled) - { + /// + public void OnActionExecuted(ActionExecutedContext context) { + if (context.Exception == null || context.ExceptionHandled) { return; } var exception = context.Exception; var now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - var model = new ExceptionModel - { + var model = new ExceptionModel { Id = Guid.NewGuid().ToString(), CreateDateTime = now, Message = exception.Message, }; - if (exception is ApiException) - { - context.Result = new ObjectResult(model) { StatusCode = 400, }; + if (exception is ApiException) { + context.Result = new ObjectResult(model) { StatusCode = this.StatusCode, }; context.ExceptionHandled = true; } var logmsg = new StringBuilder();