Skip to content

Commit

Permalink
remove references to String http responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpe7s committed Aug 30, 2024
1 parent 5a687cc commit 56cc550
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;

Expand Down Expand Up @@ -49,6 +50,10 @@ protected static <R> Function<HttpResponse<byte[]>, R> applyResponse(final Funct
return new JsonResponseController<>(adapter);
}

protected static <R> Function<HttpResponse<byte[]>, R> applyResponse(final BiFunction<byte[], JsonIterator, R> adapter) {
return new KeepJsonResponseController<>(adapter);
}

protected <R> Function<HttpResponse<byte[]>, R> wrapParser(final Function<HttpResponse<byte[]>, R> parser) {
return applyResponse == null ? parser : response -> applyResponse.test(response) ? parser.apply(response) : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ static void logBody(final HttpResponse<byte[]> httpResponse, final RuntimeExcept
logBody(httpResponse, new String(httpResponse.body()), ex);
}

static void logStringBody(final HttpResponse<String> httpResponse, final RuntimeException ex) {
logBody(httpResponse, httpResponse.body(), ex);
}

static void logBody(final HttpResponse<?> httpResponse, final String body, final RuntimeException ex) {
log.log(ERROR,
String.format("Failed to parse [httpCode:%d], [body=%s]", httpResponse.statusCode(), body),
Expand All @@ -32,13 +28,6 @@ static RuntimeException throwUncheckedIOException(final HttpResponse<?> httpResp
"HTTP request failed with [httpCode:%d], [body=%s]", httpResponse.statusCode(), body)));
}

public static void checkStringResponseCode(final HttpResponse<String> httpResponse) {
final int responseCode = httpResponse.statusCode();
if (responseCode < 200 || responseCode >= 300) {
throw throwUncheckedIOException(httpResponse, httpResponse.body());
}
}

public static void checkResponseCode(final HttpResponse<byte[]> httpResponse) {
final int responseCode = httpResponse.statusCode();
if (responseCode < 200 || responseCode >= 300) {
Expand Down

0 comments on commit 56cc550

Please sign in to comment.