BAEL-4970: Close the original response body (#10782)

Co-authored-by: Krzysztof Woyke <krzysztof.woyke.sp@lhsystems.com>
This commit is contained in:
kwoyke 2021-05-22 10:46:02 +02:00 committed by GitHub
parent 31f40d8623
commit 2553a71828
1 changed files with 6 additions and 1 deletions

View File

@ -21,7 +21,12 @@ public class ErrorResponseInterceptor implements Interceptor {
Gson gson = new Gson();
String body = gson.toJson(new ErrorMessage(response.code(), "The response from the server was not OK"));
ResponseBody responseBody = ResponseBody.create(body, APPLICATION_JSON);
ResponseBody originalBody = response.body();
if (originalBody != null) {
originalBody.close();
}
return response.newBuilder()
.body(responseBody)
.build();