Exemplo n.º 1
0
 public S3Exception(S3Error error, HttpStatusCode httpStatusCode, string responseText)
     : this(error.Message, httpStatusCode)
 {
     ErrorCode    = error.Code;
     RequestId    = error.RequestId;
     ResponseText = responseText;
 }
Exemplo n.º 2
0
        protected override async Task <Exception> GetExceptionAsync(HttpResponseMessage response)
        {
            string responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                string key = response.RequestMessage.RequestUri.AbsolutePath;

                if (key.Length > 0 && key[0] == '/')
                {
                    key = key.Substring(1);
                }

                throw StorageException.NotFound(key);
            }

            if (responseText.Contains("<Error>"))
            {
                throw new S3Exception(
                          error: S3Error.ParseXml(responseText),
                          statusCode: response.StatusCode
                          );
            }

            throw new S3Exception("Unexpected S3 error. " + response.StatusCode + ":" + responseText, response.StatusCode);
        }
Exemplo n.º 3
0
 public S3Exception(S3Error error, HttpStatusCode statusCode)
     : this(error.Message, statusCode)
 {
     ErrorCode      = error.Code;
     HttpStatusCode = statusCode;
     RequestId      = error.RequestId;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes an AmazonS3Exception with error information provided in an
 /// AmazonS3 response and the inner exception that is the cause of the exception
 /// </summary>
 /// <param name="statusCode">HTTP status code for error response</param>
 /// <param name="xml">Compete xml found in response</param>
 /// <param name="requestAddr">The S3 request url</param>
 /// <param name="responseHeaders">The response headers containing S3 specific information
 /// <param name="error">The nested exception that caused the AmazonS3Exception</param>
 /// </param>
 public AmazonS3Exception(
     HttpStatusCode statusCode,
     string xml,
     string requestAddr,
     WebHeaderCollection responseHeaders,
     S3Error error)
 {
     this.xml             = xml;
     this.statusCode      = statusCode;
     this.requestAddr     = requestAddr;
     this.responseHeaders = responseHeaders;
     if (error != null)
     {
         this.errorCode = error.Code;
         this.hostId    = error.HostId;
         this.requestId = error.RequestId;
         this.message   = error.Message;
     }
 }
Exemplo n.º 5
0
        protected override async Task <Exception> GetExceptionAsync(HttpResponseMessage response)
        {
            var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                // Consider limiting to KeyNotFound?

                throw StorageException.NotFound(response.RequestMessage.RequestUri.AbsolutePath.TrimStart('/'));
            }

            if (responseText.Contains("<Error>"))
            {
                var error = S3Error.ParseXml(responseText);

                throw new S3Exception(error, response.StatusCode, responseText);
            }

            throw new S3Exception("Unexpected S3 error. " + response.StatusCode + ":" + responseText, response.StatusCode);
        }