public void OnException(ExceptionContext context) { //var isAjax = context.HttpContext.Request.IsAjaxRequest(); //var method = context.HttpContext.Request.Method; //var requestPath = context.HttpContext.Request.Path.Value; string errorMessage = context.Exception.Message, fullException = context.Exception.StackTrace; //全局异常错误码 var errorCode = ((int)MyResultCode.GLOBAL_EXCEPTION).ToString(); if (context.Exception.GetType() == typeof(MyException)) { errorCode = ((MyException)context.Exception).Code; } //友好化处理 errorMessage = MyExceptionUtil.GetFriendlyMessage(errorMessage, fullException); //如果是 if (_env.IsDevelopment()) { errorMessage += "\n" + fullException; } //返回值处理 context.Result = CommonResult.ApiResult <string>( null, new MyErrorInfo { Code = errorCode, Message = errorMessage } ); context.HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; context.ExceptionHandled = true; }
public JsonResult ApiResult(MyResultCode code, MyResultSubCode subCode) { string language = Request.Headers["Accept-Language"]; if (string.IsNullOrEmpty(language)) { language = "zh-Hans"; } return(CommonResult.ApiResult(code, subCode, language)); }
public JsonResult ApiResult(Exception e) { string language = Request.Headers["Accept-Language"]; if (string.IsNullOrEmpty(language)) { language = "zh-Hans"; } return(CommonResult.ApiResult(e, language)); }
public IActionResult loc() { string l = string.IsNullOrEmpty(Request.Headers["Accept-Language"]) ? "zh-Hans" : Request.Headers["Accept-Language"].ToString(); try { string hello = _localizer["hello"]; return(Ok(hello)); } catch (Exception ex) { return(CommonResult.ApiResult(ex, l)); } }
public JsonResult ApiResult <T>(T data, MyErrorInfo mei = null, string dtf = "yyyy-MM-dd HH:mm:ss", List <MyKeyValue> Params = null, string IgnoreGroup = "") where T : class { return(CommonResult.ApiResult <T>(data, mei, dtf, Params, IgnoreGroup)); }