Skip to content

Fix http throwable responses #2251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
address review comments
  • Loading branch information
doxiao committed Mar 9, 2021
commit 21feb98ae39d009ebd3ba310b5d3ab64ce2500db
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -107,15 +106,14 @@ private void checkTimeout(AsyncFiber fiber) {
}

private void resume(AsyncFiber fiber, HttpResponse<String> response, Throwable throwable) {
if (throwable != null) {
if (throwable instanceof HttpTimeoutException) {
LOGGER.fine(MessageKeys.HTTP_REQUEST_TIMED_OUT, throwable.getMessage());
} else if (response == null) {
recordThrowableResponse(throwable);
}
if (throwable instanceof HttpTimeoutException) {
LOGGER.fine(MessageKeys.HTTP_REQUEST_TIMED_OUT, throwable.getMessage());
} else if (response != null) {
recordResponse(response);
} else if (throwable != null) {
recordThrowableResponse(throwable);
}

Optional.ofNullable(response).ifPresent(this::recordResponse);

fiber.resume(packet);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ public HttpResponseStep(Step next) {
public NextAction apply(Packet packet) {
return Optional.ofNullable(getResponse(packet))
.map(r -> doApply(packet, r))
.orElse(Optional.ofNullable(getThrowableResponse(packet))
.map(t -> onFailure(packet, null))
.orElse(doNext(packet)));
.orElse(handlePossibleThrowableOrContinue(packet));
}

private NextAction handlePossibleThrowableOrContinue(Packet packet) {
return Optional.ofNullable(getThrowableResponse(packet))
.map(t -> onFailure(packet, null))
.orElse(doNext(packet));
}

private Throwable getThrowableResponse(Packet packet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,14 @@ public void whenErrorResponseReceived_logMessage() {

@Test
public void whenThrowableResponseReceived_logMessage() {
Memento m = TestUtils.silenceOperatorLogger()
consoleMemento
.collectLogMessages(logRecords, HTTP_REQUEST_GOT_THROWABLE)
.withLogLevel(Level.WARNING)
.ignoringLoggedExceptions(HttpAsyncRequestStep.HttpTimeoutException.class);
.withLogLevel(Level.WARNING);
final NextAction nextAction = requestStep.apply(packet);

completeWithThrowableBeforeTimeout(nextAction, new Throwable("Test"));

assertThat(logRecords, containsWarning(HTTP_REQUEST_GOT_THROWABLE));
m.revert();
}

@Test
Expand Down