### Question:
AzureRetryableErrorHandler extends BackoffLimitedRetryHandler { @Override public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (response.getStatusCode() != 429 || isRateLimitError(response)) { return false; } try { Error error = parseError.apply(response); logger.debug("processing error: %s", error); boolean isRetryable = RETRYABLE_ERROR_CODE.equals(error.details().code()); return isRetryable ? super.shouldRetryRequest(command, response) : false; } catch (Exception ex) { logger.warn("could not parse error. Request won't be retried: %s", ex.getMessage()); return false; } } @Inject  AzureRetryableErrorHandler(ParseJson<Error> parseError); @Override boolean shouldRetryRequest(HttpCommand command, HttpResponse response);  }### Answer:
@Test public void testDoesNotRetryWhenNot429() { HttpCommand command = new HttpCommand(HttpRequest.builder().method("GET").endpoint("http: HttpResponse response = HttpResponse.builder().statusCode(400).build(); assertFalse(handler.shouldRetryRequest(command, response)); }
@Test public void testDoesNotRetryWhenRateLimitError() { HttpCommand command = new HttpCommand(HttpRequest.builder().method("GET").endpoint("http: HttpResponse response = HttpResponse.builder().statusCode(429).addHeader(HttpHeaders.RETRY_AFTER, "15").build(); assertFalse(handler.shouldRetryRequest(command, response)); }
@Test public void testDoesNotRetryWhenCannotParseError() { HttpCommand command = new HttpCommand(HttpRequest.builder().method("GET").endpoint("http: HttpResponse response = HttpResponse.builder().statusCode(429).payload("foo").build(); assertFalse(handler.shouldRetryRequest(command, response)); }
@Test public void testDoesNotRetryWhenErrorNotRetryable() { String nonRetryable = "{\"error\":{\"code\":\"ReferencedResourceNotProvisioned\",\"message\":\"Not provisioned\"}}"; HttpCommand command = new HttpCommand(HttpRequest.builder().method("GET").endpoint("http: HttpResponse response = HttpResponse.builder().statusCode(429).payload(nonRetryable).build(); assertFalse(handler.shouldRetryRequest(command, response)); }
@Test public void testRetriesWhenRetryableError() { String retryable = "{\"error\":{\"code\":\"RetryableError\",\"message\":\"Resource busy\"}}"; HttpCommand command = new HttpCommand(HttpRequest.builder().method("GET").endpoint("http: HttpResponse response = HttpResponse.builder().statusCode(429).payload(retryable).build(); assertTrue(handler.shouldRetryRequest(command, response)); }