public void OnException(ExceptionContext context) { #if DEBUG context.Result = new ClientResult(ResultDto.DefaultError((int)ResultState.Unknow, context.Exception.Message + Environment.NewLine + context.Exception.StackTrace)); #else context.Result = new ClientResult(ResultDto.DefaultError((int)ResultState.Unknow, "未知错误")); #endif LogHelper.Error(context.Exception.Message + Environment.NewLine + context.Exception.StackTrace); context.ExceptionHandled = true; }
public override void OnActionExecuting(ActionExecutingContext context) { //加入时间戳-接口计时需要 context.HttpContext.Request.Headers.Add("X-Time", Environment.TickCount.ToString()); var err = ""; foreach (var propname in context.ModelState.Keys) { foreach (var temp in context.ModelState[propname].Errors) { err = $"参数{propname}错误,{temp.ErrorMessage}"; } } if (!context.ModelState.IsValid) { context.Result = new ClientResult(ResultDto.DefaultError(ResultState.GlobalParameterError, err)); } }