We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fd71e2c commit 02595baCopy full SHA for 02595ba
libraries-http-2/src/main/java/com/baeldung/okhttp/interceptors/ErrorResponseInterceptor.java
@@ -21,7 +21,12 @@ public Response intercept(Chain chain) throws IOException {
21
Gson gson = new Gson();
22
String body = gson.toJson(new ErrorMessage(response.code(), "The response from the server was not OK"));
23
ResponseBody responseBody = ResponseBody.create(body, APPLICATION_JSON);
24
-
+
25
+ ResponseBody originalBody = response.body();
26
+ if (originalBody != null) {
27
+ originalBody.close();
28
+ }
29
30
return response.newBuilder()
31
.body(responseBody)
32
.build();
0 commit comments