コード例 #1
0
 private void populateFromMWSException(MwsException e)
 {
     if (e.StatusCode != null)
     {
         this.statusCode = (int)e.StatusCode;
     }
     if (e.Message != null)
     {
         this.message = e.Message;
     }
     if (e.errorCode != null)
     {
         this.errorCode = e.ErrorCode;
     }
     if (e.errorType != null)
     {
         this.errorType = e.ErrorType;
     }
     if (e.detail != null)
     {
         this.detail = e.Detail;
     }
     if (e.xml != null)
     {
         this.xml = e.XML;
     }
     if (e.ResponseHeaderMetadata != null)
     {
         this.rhmd = e.ResponseHeaderMetadata;
     }
 }
コード例 #2
0
 /// <summary>
 /// Initialize and set cause from another exception.
 /// <para>
 /// If cause is an MwsException, copies exception's attributes to this
 /// one, ignoring the statusCode and message parameters that were passed in.
 /// </para>
 /// </summary>
 /// <param name="statusCode">HTTP status code for error response.</param>
 /// <param name="message">Error message from HTTP header.</param>
 /// <param name="cause">Inner exception.</param>
 ////
 public MwsException(int statusCode, string message, Exception cause)
     : base(message, cause)
 {
     if (cause is MwsException)
     {
         MwsException e = (MwsException)cause;
         this.statusCode = (int)e.StatusCode;
         this.message    = e.Message;
         this.errorCode  = e.ErrorCode;
         this.errorType  = e.ErrorType;
         this.detail     = e.Detail;
         this.xml        = e.XML;
         this.rhmd       = e.ResponseHeaderMetadata;
     }
     else
     {
         this.statusCode = statusCode;
         this.message    = message;
     }
 }
コード例 #3
0
ファイル: MwsException.cs プロジェクト: qida/UprightBuz
 private void populateFromMWSException( MwsException e )
 {
     if (e.StatusCode != null) this.statusCode = (int)e.StatusCode;
     if (e.Message != null) this.message = e.Message;
     if (e.errorCode != null) this.errorCode = e.ErrorCode;
     if (e.errorType != null) this.errorType = e.ErrorType;
     if (e.detail != null) this.detail = e.Detail;
     if (e.xml != null) this.xml = e.XML;
     if (e.ResponseHeaderMetadata != null) this.rhmd = e.ResponseHeaderMetadata;
 }
コード例 #4
0
ファイル: MwsAQCall.cs プロジェクト: pedrohma/e-commerce-apis
        /// <summary>
        /// Creates a request and invokes it
        /// </summary>
        /// <returns></returns>
        /// <exception cref="MwsException">Exceptions from invoking the request</exception>
        public IMwsReader invoke()
        {
            string         responseBody;
            string         message;
            HttpStatusCode statusCode = default(HttpStatusCode);

            /* Add required request parameters */
            AddRequiredParameters();
            string queryString = GetParametersAsString(parameters);
            int    retries     = 0;

            do
            {
                /* Submit the request and read response body */
                try
                {
                    request = connection.GetHttpClient(serviceEndPoint.URI);
                    byte[] requestData = new UTF8Encoding().GetBytes(queryString);
                    request.ContentLength = requestData.Length;
                    using (Stream requestStream = request.GetRequestStream())
                    {
                        requestStream.Write(requestData, 0, requestData.Length);
                    }
                    using (HttpWebResponse httpResponse = request.GetResponse() as HttpWebResponse)
                    {
                        statusCode             = httpResponse.StatusCode;
                        message                = httpResponse.StatusDescription;
                        ResponseHeaderMetadata = GetResponseHeaderMetadata(httpResponse);
                        StreamReader reader = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8);
                        responseBody = reader.ReadToEnd();
                    }
                    if (statusCode == HttpStatusCode.OK)
                    {
                        return(new MwsXmlReader(responseBody));
                    }
                    MwsException e = new MwsException((int)statusCode, message, null, null, responseBody, ResponseHeaderMetadata);

                    if (statusCode == HttpStatusCode.InternalServerError)
                    {
                        if (PauseIfRetryNeeded(retries++))
                        {
                            continue;
                        }
                    }
                    throw e;
                }
                /* Web exception is thrown on unsuccessful responses */
                catch (WebException we)
                {
                    using (HttpWebResponse httpErrorResponse = (HttpWebResponse)we.Response as HttpWebResponse)
                    {
                        if (httpErrorResponse == null)
                        {
                            throw new MwsException(we);
                        }
                        statusCode = httpErrorResponse.StatusCode;
                        using (StreamReader reader = new StreamReader(httpErrorResponse.GetResponseStream(), Encoding.UTF8))
                        {
                            responseBody = reader.ReadToEnd();
                        }
                    }
                    //retry logic
                    if (PauseIfRetryNeeded(retries++))
                    {
                        continue;
                    }
                    throw new MwsException((int)statusCode, null, null, null, responseBody, null);
                }

                /* Catch other exceptions, attempt to convert to formatted exception,
                 * else rethrow wrapped exception */
                catch (Exception e)
                {
                    throw new MwsException(e);
                }
            } while (true);
        }