in sdk/core/azure-core-http/src/main/java/com/azure/android/core/http/policy/RetryPolicy.java [165:194]
public Duration calculateRetryDelay(HttpResponse response, Throwable exception, int retryAttempts) {
if (exception != null) {
return this.retryStrategy.calculateRetryDelay(null, exception, retryAttempts);
} else {
final int code = response.getStatusCode();
if (code == 429) {
// Too Many Requests.
// https://docs.microsoft.com/en-us/rest/api/cosmos-db/common-cosmosdb-rest-response-headers
final String retryAfterHeader = response.getHeaderValue("x-ms-retry-after-ms");
if (retryAfterHeader != null) {
return Duration.of(Integer.parseInt(retryAfterHeader), ChronoUnit.MILLIS);
}
}
if (code == 429 || code == 503) {
// Too Many Requests OR Service Unavailable
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
final String retryAfterHeader = response.getHeaderValue("Retry-After");
if (retryAfterHeader != null) {
try {
return Duration.between(OffsetDateTime.now(),
OffsetDateTime.parse(retryAfterHeader, DateTimeFormatter.RFC_1123_DATE_TIME));
} catch (Exception ignored) {
return Duration.of(Integer.parseInt(retryAfterHeader), ChronoUnit.SECONDS);
}
}
}
return this.retryStrategy.calculateRetryDelay(response, null, retryAttempts);
}
}