Skip to content

Commit

Permalink
fix silly mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritham Marupaka committed Jan 10, 2025
1 parent bcbf495 commit c67cb58
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.io.CharStreams;
import com.google.common.net.HttpHeaders;
import com.google.common.primitives.Longs;
import com.palantir.conjure.java.api.errors.QosException;
Expand All @@ -43,8 +42,6 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
Expand All @@ -71,6 +68,8 @@ final class EndpointErrorDecoder<T> {
private static final Encoding JSON_ENCODING = Encodings.json();
private static final Deserializer<NamedError> NAMED_ERROR_DESERIALIZER =
JSON_ENCODING.deserializer(new TypeMarker<>() {});
private static final Deserializer<SerializableError> SERIALIZABLE_ERROR_DESERIALIZER =
JSON_ENCODING.deserializer(new TypeMarker<>() {});
private final Map<String, Encoding.Deserializer<? extends T>> errorNameToJsonDeserializerMap;

EndpointErrorDecoder(Map<String, TypeMarker<? extends T>> errorNameToTypeMap) {
Expand All @@ -83,11 +82,11 @@ final class EndpointErrorDecoder<T> {
Maps.transformValues(errorNameToTypeMap, maybeJsonEncoding.orElse(JSON_ENCODING)::deserializer));
}

public boolean isError(Response response) {
boolean isError(Response response) {
return 300 <= response.code() && response.code() <= 599;
}

public T decode(Response response) {
T decode(Response response) {
if (log.isDebugEnabled()) {
log.debug("Received an error response", diagnosticArgs(response));
}
Expand Down Expand Up @@ -187,15 +186,14 @@ private T decodeInternal(Response response) {
}

private static RemoteException createRemoteException(byte[] body, int code) throws IOException {
SerializableError serializableError = JSON_ENCODING
.deserializer(new TypeMarker<SerializableError>() {})
.deserialize(new ByteArrayInputStream(body));
SerializableError serializableError =
SERIALIZABLE_ERROR_DESERIALIZER.deserialize(new ByteArrayInputStream(body));
return new RemoteException(serializableError, code);
}

private static byte[] toByteArray(InputStream body) throws IOException {
try (Reader reader = new InputStreamReader(body, StandardCharsets.UTF_8)) {
return CharStreams.toString(reader).getBytes(StandardCharsets.UTF_8);
try (body) {
return body.readAllBytes();
}
}

Expand Down

0 comments on commit c67cb58

Please sign in to comment.