public void OnException(ExceptionContext filterContext) { ResponseMessage resp = new ResponseMessage { IsSuccess = false, ErrorCode = "00001", Message = filterContext.Exception.Message }; if (filterContext.Exception is RShopException) { RShopException meEx = filterContext.Exception as RShopException; resp.ErrorCode = meEx.ErrorCode; } Logger.Error(filterContext.Exception); filterContext.Result = new JsonResult { Data = resp, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }
public override void OnException(HttpActionExecutedContext actionExecutedContext) { ResponseMessage resp = new ResponseMessage { IsSuccess = false, ErrorCode = "00001", Message = actionExecutedContext.Exception.Message }; if (actionExecutedContext.Exception is RShopException) { RShopException meEx = actionExecutedContext.Exception as RShopException; resp.ErrorCode = String.IsNullOrEmpty(meEx.ErrorCode) ? "00002" : meEx.ErrorCode; Logger.Warn(actionExecutedContext.Exception); } else { Logger.Error(actionExecutedContext.Exception); } actionExecutedContext.Response = actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse <ResponseMessage>(resp); base.OnException(actionExecutedContext); }