Esempio n. 1
0
 public ServerResponseException(int?httpCode, SdkError sdkError) : base(httpCode, sdkError)
 {
     this.HttpStatusCode = httpCode;
     this.ErrorCode      = sdkError.ErrorCode;
     this.ErrorMsg       = sdkError.ErrorMsg;
     this.RequestId      = sdkError.RequestId;
 }
Esempio n. 2
0
 public ClientRequestException(int?httpCode, SdkError sdkError) : base(httpCode, sdkError)
 {
     this.HttpStatusCode = httpCode;
     this.ErrorCode      = sdkError.ErrorCode;
     this.ErrorMsg       = sdkError.ErrorMsg;
     this.RequestId      = sdkError.RequestId;
 }
Esempio n. 3
0
        /// <summary>
        /// Validates the response.
        /// </summary>
        /// <typeparam name="V"></typeparam>
        /// <typeparam name="E"></typeparam>
        /// <typeparam name="C"></typeparam>
        /// <param name="restResponse">The rest response.</param>
        /// <exception cref="PayUException"></exception>
        public static void ValidateResponse <V, E, C>(this IRestResponse <V, E, C> restResponse)
        {
            if (restResponse.Error != null)
            {
                if (restResponse.Error is SdkError)
                {
                    SdkError sdkError = restResponse.Error as SdkError;
                    RestResponseExtensionsUtils.FormatSdkError(sdkError);
                }
            }

            RestResponseExtensionsUtils.ValidateResponseCommon(restResponse);
        }
        public static ServiceResponseException MapException(int?httpStatusCode, SdkError sdkError)
        {
            if (httpStatusCode >= 400 && httpStatusCode < 500)
            {
                return(new ClientRequestException(httpStatusCode, sdkError));
            }

            if (httpStatusCode >= 500 && httpStatusCode < 600)
            {
                return(new ServerResponseException(httpStatusCode, sdkError));
            }

            return(new ServiceResponseException(httpStatusCode, sdkError));
        }
Esempio n. 5
0
        /// <summary>
        /// Formats the SDK error.
        /// </summary>
        /// <param name="sdkError">The SDK error.</param>
        /// <exception cref="PayUException"></exception>
        private static void FormatSdkError(SdkError sdkError)
        {
            StringBuilder errorList = new StringBuilder();

            if (sdkError.ErrorList != null && sdkError.ErrorList.Count > 0)
            {
                foreach (string error in sdkError.ErrorList)
                {
                    errorList.AppendLine(error);
                }
            }

            throw new PayUException(ErrorCode.INVALID_PARAMETERS,
                                    string.Format(PayUSdkMessages.FormatErrorSdkException, sdkError.ErrorType,
                                                  sdkError.Description, errorList));
        }
Esempio n. 6
0
        /// <summary>
        /// Validates the response.
        /// </summary>
        /// <typeparam name="V"></typeparam>
        /// <typeparam name="E"></typeparam>
        /// <param name="restResponse">The rest response.</param>
        public static void ValidateResponse <V, E>(this IRestResponse <V, E> restResponse)
        {
            if (restResponse.Error != null)
            {
                if (restResponse.Error is SdkError)
                {
                    SdkError sdkError = restResponse.Error as SdkError;
                    RestResponseExtensionsUtils.FormatSdkError(sdkError);
                }
                if (restResponse.Error is PaymentResponse)
                {
                    PaymentResponse paymentResponse = restResponse.Error as PaymentResponse;

                    throw new PayUException(ErrorCode.INVALID_PARAMETERS,
                                            string.Format("{0} {1} {2}", paymentResponse.ResponseCode, paymentResponse.Error, paymentResponse.MessageError));
                }
            }

            RestResponseExtensionsUtils.ValidateResponseCommon(restResponse);
        }