Exemple #1
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);
        }
Exemple #2
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);
        }