Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public boolean retryHttpResponse(final HttpResponse response)
return code == HttpResponseStatus.BAD_GATEWAY.getCode()
|| code == HttpResponseStatus.SERVICE_UNAVAILABLE.getCode()
|| code == HttpResponseStatus.GATEWAY_TIMEOUT.getCode()

// 401 can happen from things like expiration and might be retryable
|| code == HttpResponseStatus.UNAUTHORIZED.getCode()
// Technically shouldn't retry this last one, but servers sometimes return HTTP 500 for retryable errors.
|| code == HttpResponseStatus.INTERNAL_SERVER_ERROR.getCode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,23 @@ private <T> OngoingStubbing<ListenableFuture<Either<StringFullResponseHolder, T>
);
}

@Test
public void test_request_authErrorRetry() throws Exception
{
final RequestBuilder requestBuilder = new RequestBuilder(HttpMethod.GET, "/foo");
final ImmutableMap<String, String> expectedResponseObject = ImmutableMap.of("foo", "bar");

// Unauthorized response from SERVER1, then OK response.
stubLocatorCall(locations(SERVER1, SERVER2));
expectHttpCall(requestBuilder, SERVER1)
.thenReturn(errorResponse(HttpResponseStatus.UNAUTHORIZED, null, "unauthorized"))
.thenReturn(valueResponse(expectedResponseObject));

serviceClient = makeServiceClient(StandardRetryPolicy.unlimited());
final Map<String, String> response = doRequest(serviceClient, requestBuilder);
Assert.assertEquals(expectedResponseObject, response);
}

private void stubLocatorCall(final ServiceLocations locations)
{
stubLocatorCall(Futures.immediateFuture(locations));
Expand Down
Loading