@Override public Optional<IOException> handle(Response response) { if (response.isSuccessful() || response.code() == MoreHttpCodes.SWITCHING_PROTOCOLS) { return Optional.empty(); } try { String body = response.body() != null && response.body().byteStream() != null ? toString(response.body().byteStream()) : "<empty>"; return Optional.of(new SafeIoException( String.format("Error %s. (Failed to parse response body as SerializableError.)", response.code()), SafeArg.of("code", response.code()), UnsafeArg.of("body", body), SafeArg.of("contentType", response.header(HttpHeaders.CONTENT_TYPE)))); } catch (IOException e) { return Optional.of(new IOException("Failed to read response body", e)); } }
private static Optional<IOException> decode(String contentType, int status, @CheckForNull String body) { return handler.handle(response(status, contentType, body)); }
@Override public Optional<IOException> handle(Response response) { if (response.isSuccessful() || response.code() == MoreHttpCodes.SWITCHING_PROTOCOLS) { return Optional.empty(); } try { String body = response.body() != null && response.body().byteStream() != null ? toString(response.body().byteStream()) : "<empty>"; return Optional.of(new SafeIoException( String.format("Error %s. (Failed to parse response body as SerializableError.)", response.code()), SafeArg.of("code", response.code()), UnsafeArg.of("body", body), SafeArg.of("contentType", response.header(HttpHeaders.CONTENT_TYPE)))); } catch (IOException e) { return Optional.of(new IOException("Failed to read response body", e)); } }