public static IKnowException FromKnowException(IKnowException knowException) { return(new KnowException() { Message = knowException.Message, ErrorCode = knowException.ErrorCode, ErrorData = knowException.ErrorData }); }
public void OnException(ExceptionContext context) { IKnowException knowException = context.Exception as IKnowException; if (knowException == null) { knowException = KnowException.Unkown; context.HttpContext.Response.StatusCode = StatusCodes.Status500InternalServerError; } else { knowException = KnowException.FromKnowException(knowException); context.HttpContext.Response.StatusCode = StatusCodes.Status200OK; } context.Result = new JsonResult(knowException) { ContentType = "application/json; charset=utf-8" }; }
public override void OnException(ExceptionContext context) { IKnowException knowException = context.Exception as IKnowException; if (knowException == null) { var logger = context.HttpContext.RequestServices.GetService <ILogger <MyExceptionFilterAttribute> >(); logger.LogError(context.Exception, context.Exception.Message); knowException = KnowException.Unknown; context.HttpContext.Response.StatusCode = StatusCodes.Status500InternalServerError; } else { knowException = KnowException.FromKnownException(knowException); context.HttpContext.Response.StatusCode = StatusCodes.Status200OK; } context.Result = new JsonResult(knowException) { ContentType = "application/json; charset=utf-8" }; }
public static KnowException FromKnowException(IKnowException exception) { return(new KnowException { ErrorCode = exception.ErrorCode, Message = exception.Message, ErrorData = exception.ErrorData }); }