| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using Azure.Core; |
| | 6 | |
|
| | 7 | | namespace Azure.Storage |
| | 8 | | { |
| | 9 | | internal class StorageResponseClassifier : ResponseClassifier |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// The secondary URI to be used for retries on failed read requests |
| | 13 | | /// </summary> |
| 80 | 14 | | public Uri SecondaryStorageUri { get; set; } |
| | 15 | |
|
| | 16 | | /// <summary> |
| | 17 | | /// Overridden version of IsRetriableResponse that allows for Storage specific retry logic. |
| | 18 | | /// </summary> |
| | 19 | | /// <param name="message">The message containing both Response and Request</param> |
| | 20 | | /// <returns></returns> |
| | 21 | | public override bool IsRetriableResponse(HttpMessage message) |
| | 22 | | { |
| | 23 | | // If secondary storage Uri was specified, we want to retry if the current attempt was against the secondary |
| | 24 | | // get a response of NotFound. This is because the resource may not have been propagated to secondary Uri ye |
| 22 | 25 | | if (SecondaryStorageUri != null && |
| 22 | 26 | | message.Request.Uri.Host == SecondaryStorageUri.Host && |
| 22 | 27 | | message.Response.Status == Constants.HttpStatusCode.NotFound) |
| | 28 | | { |
| 2 | 29 | | return true; |
| | 30 | | } |
| | 31 | |
|
| | 32 | | // Retry select Storage service error codes |
| 20 | 33 | | if (message.Response.Status >= 400 && |
| 20 | 34 | | message.Response.Headers.TryGetValue(Constants.HeaderNames.ErrorCode, out var error)) |
| | 35 | | { |
| | 36 | | switch (error) |
| | 37 | | { |
| | 38 | | case Constants.ErrorCodes.InternalError: |
| | 39 | | case Constants.ErrorCodes.OperationTimedOut: |
| | 40 | | case Constants.ErrorCodes.ServerBusy: |
| 12 | 41 | | return true; |
| | 42 | | } |
| | 43 | | } |
| 8 | 44 | | return base.IsRetriableResponse(message); |
| | 45 | | } |
| | 46 | | } |
| | 47 | | } |