Code: Select all
private static void printPossibleErrors(Response response) throws IOException {
if (Objects.nonNull(response) && !response.isSuccessful()) {
try (okhttp3.Response raw = response.raw(); ResponseBody errorBody = response.errorBody()) {
String fullUrl = Optional.ofNullable(raw)
.map(okhttp3.Response::request)
.map(Request::url)
.map(HttpUrl::toString)
.orElseGet(() -> "");
log.info(
"MY api calling {} error response with code: {}, body: {}",
fullUrl,
response.code(),
errorBody.string());
}
}
}
java.lang.IllegalStateException: Cannot read raw Response Body of a
converted Body.
Ich habe herumgelesen und festgestellt, dass ein ResponseBody von Retrofit dies nicht kann zweimal gelesen werden. In meinem Code lese ich jedoch die Rohantwort und den Fehlertext, bei denen es sich um separate Objekte handelt:
Code: Select all
public final class Response {
private final okhttp3.Response rawResponse;
private final T body;
private final ResponseBody errorBody;
// ...
}
Mobile version