Skip to content

Commit 4423978

Browse files
authored
Merge pull request #38 from auth0/fixed-close-response-body
Close the ResponseBody after its parsed
2 parents f8e3792 + 2c9a8e8 commit 4423978

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/main/java/com/auth0/net/CustomRequest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ protected T parseResponse(Response response) throws Auth0Exception {
5757
throw createResponseException(response);
5858
}
5959

60-
String payload;
61-
try {
62-
payload = response.body().string();
60+
try (ResponseBody body = response.body()) {
61+
String payload = body.string();
6362
return mapper.readValue(payload, tType);
6463
} catch (IOException e) {
6564
throw new APIException("Failed to parse json body", response.code(), e);
@@ -98,8 +97,8 @@ protected RequestBody createBody() throws Auth0Exception {
9897

9998
protected Auth0Exception createResponseException(Response response) {
10099
String payload = null;
101-
try {
102-
payload = response.body().string();
100+
try (ResponseBody body = response.body()) {
101+
payload = body.string();
103102
MapType mapType = mapper.getTypeFactory().constructMapType(HashMap.class, String.class, Object.class);
104103
Map<String, Object> values = mapper.readValue(payload, mapType);
105104
return new APIException(values, response.code());

0 commit comments

Comments
 (0)