Example #1
0
        /// <summary>
        /// Parse an S3 Error response and create an S3PostUploadException
        /// </summary>
        /// <param name="response">The response from S3</param>
        /// <returns>An S3PostUploadException with the information from the response</returns>
        public static S3PostUploadException FromResponse(HttpWebResponse response)
        {
            var serializer = new XmlSerializer(typeof(S3PostUploadError));

            S3PostUploadError err = null;

            try
            {
                err = serializer.Deserialize(response.GetResponseStream()) as S3PostUploadError;
            }
            catch
            {
                return(new S3PostUploadException("Unknown", "Unknown error"));
            }

            var ex = new S3PostUploadException(err.ErrorCode, err.ErrorMessage)
            {
                RequestId = err.RequestId,
                HostId    = err.HostId,
            };

            ex.StatusCode  = response.StatusCode;
            ex.ExtraFields = new Dictionary <string, string>();
            if (err.elements != null)
            {
                foreach (var f in err.elements)
                {
                    ex.ExtraFields.Add(f.LocalName, f.InnerText);
                }
            }

            return(ex);
        }
        public static S3PostUploadException FromResponse(HttpWebResponse response)
        {
            XmlSerializer     xmlSerializer     = new XmlSerializer(typeof(S3PostUploadError));
            S3PostUploadError s3PostUploadError = null;

            try
            {
                s3PostUploadError = (xmlSerializer.Deserialize(response.GetResponseStream()) as S3PostUploadError);
            }
            catch
            {
                return(new S3PostUploadException("Unknown", "Unknown error"));
            }
            S3PostUploadException ex = new S3PostUploadException(s3PostUploadError.ErrorCode, s3PostUploadError.ErrorMessage)
            {
                RequestId = s3PostUploadError.RequestId,
                HostId    = s3PostUploadError.HostId
            };

            ex.StatusCode  = response.StatusCode;
            ex.ExtraFields = new Dictionary <string, string>();
            if (s3PostUploadError.elements != null)
            {
                XmlElement[] elements = s3PostUploadError.elements;
                foreach (XmlElement xmlElement in elements)
                {
                    ex.ExtraFields.Add(xmlElement.LocalName, xmlElement.InnerText);
                }
            }
            return(ex);
        }