/// <summary> /// 格式化异常 /// </summary> /// <param name="ex"></param> private ExceptionResponse FormatException(Exception ex) { ExceptionResponse exceptionResponse; if (ex is BusinessException <string> ) { var data = ServiceProvider.Deserialize <dynamic>(ex.Message); exceptionResponse = new ExceptionResponse(HttpStatus.Err.Id, data.code == null || data.code == "" ? ErrCode.SystemError.Code : data.code.ToString(), data.content.ToString()); } else if (ex is BusinessException) { var data = ServiceProvider.Deserialize <dynamic>(ex.Message); exceptionResponse = new ExceptionResponse(HttpStatus.Err.Id, data.code.ToString(), data.content.ToString()); } else if (ex is AuthException) { exceptionResponse = new ExceptionResponse(HttpStatus.Unauthorized.Id, ErrCode.Unauthorized.Code, ex.Message); } else if (ex is RepeatException) { exceptionResponse = new ExceptionResponse(HttpStatus.Unauthorized.Id, ErrCode.Unauthorized.Code, ex.Message); } else { if (ex is RpcException || ex.InnerException is RpcException) { exceptionResponse = FormatRpcException(ex); } else { exceptionResponse = new ExceptionResponse(HttpStatus.Err.Id, ErrCode.SystemError.Code, "系统繁忙,请稍后再试"); } ServiceProvider.GetLogService().Error("未捕获的异常", ex); } return(exceptionResponse); }