예제 #1
0
 /// <summary>
 /// 返回异常编号
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 protected internal JsonResult JResult(ErrorCode code)
 {
     return(Json(new
     {
         Code = code,
         ErrorDesc = code.GetDescription()
     }, JsonRequestBehavior.AllowGet));
 }
 public static void VerifyNotSuccessResponseWithErrorCodeAndMessage <T>(this ApiResponse <T> response, ErrorCode errorCode,
                                                                        int statusCode = 400)
 {
     response.StatusCode.Should().Be(statusCode);
     response.ResponseException.Should().NotBeNull();
     response.IsSuccess.Should().BeFalse();
     response.ResponseException !.ErrorCode.Should().Be(errorCode);
     response.ResponseException.ErrorMessage.Should().NotBeNull(errorCode.GetDescription());
 }
예제 #3
0
 public static ErrorModel FromErrorCode(ErrorCode error, string message = null)
 {
     return(new ErrorModel
     {
         ErrorCode = error,
         Display = error.GetDisplayText(),
         Message = message ?? error.GetDescription()
     });
 }
예제 #4
0
 /// <summary>
 /// 返回异常编号附带自定义消息
 /// </summary>
 /// <param name="code"></param>
 /// <param name="appendMsg"></param>
 /// <returns></returns>
 protected internal JsonResult JResult(ErrorCode code, string appendMsg)
 {
     return(Json(new
     {
         Code = code,
         ErrorDesc = code.GetDescription(),
         Append = appendMsg
     }, JsonRequestBehavior.AllowGet));
 }
예제 #5
0
 /// <summary>
 /// Generate an instance of <see cref="ApiResponseModel{T}"/> that indicates a non-successful operation, taking an error code..
 /// </summary>
 /// <param name="errorCode">The unique code for this specific error that occurred during the operation.</param>
 /// <returns>An instance of <see cref="ApiResponseModel{T}"/> with an error code.</returns>
 protected ApiResponseModel <short?> GenerateErrorResponse(ErrorCode errorCode)
 {
     return(new ApiResponseModel <short?>
     {
         ErrorCode = (int)errorCode,
         ErrorMessage = errorCode.GetDescription(),
         Result = null
     });
 }
예제 #6
0
        public ApiError(ErrorCode code, object param = null)
        {
            Code    = code;
            Message = code.GetDescription();

            if (param != null)
            {
                Message = string.Format(Message, param);
            }
        }
        public ActionResult GetErrInfo(ErrorCode errCode)
        {
            this.Response.StatusCode = (int)HttpStatusCode.BadRequest;
            var errInfo = new ErrorInfo()
            {
                errorCode    = (int)errCode,
                errorMessage = errCode.GetDescription()
            };

            return(Json(errInfo));
        }
예제 #8
0
 /// <summary>
 /// 支付接口接受返回参数
 /// </summary>
 /// <param name="response"></param>
 /// <param name="errorCode"></param>
 /// <returns></returns>
 public static InnerResponse ToResponse(this InnerResponse response, ErrorCode errorCode)
 {
     response.ErrorCode = errorCode.GetValue();
     response.Message   = errorCode.GetDescription();
     response.Success   = false;
     if (errorCode == ErrorCode.Code100)
     {
         response.Success = true;
     }
     return(response);
 }
        private ResponseErp ExceptionConvert(Exception ex)
        {
            ResponseErp _result       = new ResponseErp();
            string      StackTraceMsg = string.Empty;

            StackTraceMsg = ex.StackTrace;
            //map error code, message
            ErrorCode error = EnumUtil.GetEnum <ErrorCode>(ex.Message);

            _result.code = error.ToString();
            if (_result.code == ErrorCode.U000.ToString())
            {
                _result.message = ex.Message;
            }
            else
            {
                _result.message = error.GetDescription();
            }
            _result.status = "F";

            return(_result);
        }
예제 #10
0
 public Response(ErrorCode errorCode)
 {
     code    = (int)errorCode;
     message = errorCode.GetDescription();
 }
예제 #11
0
 /// <summary>
 /// 支付接口返回参数方法
 /// </summary>
 /// <param name="response">接受参数实体</param>
 /// <param name="errorCode">参数接口枚举</param>
 /// <returns></returns>
 public static Response ToResponse(this Response response, ErrorCode errorCode)
 {
     response.ErrorCode = errorCode.GetValue();
     response.Message   = errorCode.GetDescription();
     return(response);
 }
예제 #12
0
 public BaseException(ErrorCode errorCode, string message = null)
     : base(message)
 {
     ErrorCode = errorCode;
     _error    = new ErrorDTO(ErrorCode, message ?? ErrorCode.GetDescription());
 }
예제 #13
0
 public InvalidPermissionException(ErrorCode errorCode, string message = null)
     : base(message)
 {
     this.ErrorCode = errorCode;
     _error         = new ErrorDTO(this.ErrorCode, message ?? ErrorCode.GetDescription());
 }
예제 #14
0
 public NotFoundException(ErrorCode errorCode, string message = null)
     : base(message)
 {
     this.ErrorCode = errorCode;
     _error         = new ErrorDTO(this.ErrorCode, message ?? ErrorCode.GetDescription());
 }
예제 #15
0
 public static ApiResult Failed(ErrorCode errorCode, object result, HttpCode httpCode = HttpCode.BadRequest) => new ApiResult
 {
     HttpCode = httpCode,
     Value    = new ApiJsonResult <object>((int)errorCode, errorCode.GetDescription(), result)
 };
예제 #16
0
 public BusinessException(ErrorCode code) : base((int)code, code.GetDescription())
 {
 }
예제 #17
0
 public WebResult <Y> Result <Y>(Y model, ErrorCode code)
 {
     return(new WebResult <Y> {
         Code = code, Result = model, Append = code.GetDescription()
     });
 }
예제 #18
0
        public ResponseAPI Execute(HttpContext context, dynamic dataReq = null)
        {
            ResponseAPI res = new ResponseAPI();

            StringValues HToken;

            context.Request.Headers.TryGetValue("Token", out HToken);
            Token = HToken.ToString();

            DateTime StartTime     = DateTime.Now;
            string   StackTraceMsg = string.Empty;

            try
            {
                StringValues HAccessToken;
                context.Request.Headers.TryGetValue("AccessToken", out HAccessToken);
                AccessToken = HAccessToken.ToString();

                IPHostEntry heserver = Dns.GetHostEntry(Dns.GetHostName());
                IPAddress = /*string.Join(',', heserver.AddressList.Select(x => x.ToString()).ToList());*/ context.Connection.RemoteIpAddress.ToString();

                StringValues HUserAgent;
                context.Request.Headers.TryGetValue("User-Agent", out HUserAgent);
                UserAgent = HUserAgent.ToString();

                StringValues HRecaptchaResponse;
                context.Request.Headers.TryGetValue("RecaptchaResponse", out HRecaptchaResponse);
                RecaptchaResponse = HRecaptchaResponse.ToString();

                // if (!this.GetType().Name.Equals("OauthAccessTokenGet")) this.ValidatePermission();

                /*
                 *   StringValues Husercode;
                 *   context.Request.Headers.TryGetValue("UserCode", out Husercode);
                 *   UserCode = Husercode.ToString();
                 */

                if (dataReq != null)
                {
                    try
                    {
                        dataReq = this.MappingRequest(dataReq);
                    }
                    catch (Exception)
                    {
                        dataReq = this.MappingRequestArr(dataReq);
                    }
                }

                this.ExecuteChild(dataReq, res);

                res.code    = "S0001";
                res.message = "SUCCESS";
                res.status  = "S";
            }
            catch (Exception ex)
            {
                StackTraceMsg = ex.StackTrace;
                //map error code, message
                ErrorCode error = EnumUtil.GetEnum <ErrorCode>(ex.Message);
                res.code = error.ToString();
                if (res.code == ErrorCode.U000.ToString())
                {
                    res.message = ex.Message;
                }
                else
                {
                    res.message = error.GetDescription();
                }

                res.status = "F";
            }
            finally
            {
                ASSETKKF_ADO.Mssql.Mcis.muAPILogAdo.GetInstant().Insert(new ASSETKKF_MODEL.Data.Mssql.Mcis.muAPILog()
                {
                    Token   = Token,
                    APIName = this.GetType().Name,
                    //RefID = this.Logger.RefID,
                    ServerName    = Environment.MachineName,
                    StartDate     = StartTime,
                    EndDate       = DateTime.Now,
                    Status        = res.status,
                    StatusMessage = res.message,
                    Input         = this.GetType().Name.Equals("OauthLogin") ? "" : JsonConvert.SerializeObject(dataReq),
                    Output        = JsonConvert.SerializeObject(res),
                    Remark        = StackTraceMsg
                });
            }
            return(res);
        }
예제 #19
0
 /// <summary>
 /// APIResponse
 /// </summary>
 /// <param name="code"></param>
 /// <param name="message"></param>
 public ApiResponse(ErrorCode code, string message = null)
 {
     Code = code;
     Msg  = message ?? code.GetDescription();
 }
예제 #20
0
 /// <summary>
 /// Gets the default message for the error code enum (via the description attribute).
 /// </summary>
 /// <param name="code">The error code to get the message for.</param>
 /// <param name="propertyName">A specific property name to pass in to prepend to the message (Invalid {propertyName}: {message})</param>
 /// <returns></returns>
 public static string GetErrorMessage(this ErrorCode code, string propertyName = null) =>
 $"{(!string.IsNullOrWhiteSpace(propertyName) ? $"Invalid {propertyName}: " : "")}{code.GetDescription()}";
예제 #21
0
 /// <inheritdoc />
 /// <summary>
 /// ctor.
 /// </summary>
 public PlatformException(ErrorCode code) : base(code.GetDescription(), new Exception(code.GetDescription()))
 {
     ErrorCode = code;
 }