diff --git a/src/main/resources/handlebars/Java/libraries/retrofit/auth/OAuth.mustache b/src/main/resources/handlebars/Java/libraries/retrofit/auth/OAuth.mustache index a88378f3e2..4c39f4e629 100644 --- a/src/main/resources/handlebars/Java/libraries/retrofit/auth/OAuth.mustache +++ b/src/main/resources/handlebars/Java/libraries/retrofit/auth/OAuth.mustache @@ -113,8 +113,14 @@ public class OAuth implements Interceptor { // 401/403 most likely indicates that access token has expired. Unless it happens two times in a row. if ( response != null && (response.code() == HTTP_UNAUTHORIZED || response.code() == HTTP_FORBIDDEN) && updateTokenAndRetryOnAuthorizationFailure ) { - if (updateAccessToken(requestAccessToken)) { - return retryingIntercept( chain, false ); + try { + if (updateAccessToken(requestAccessToken)) { + response.body().close(); + return retryingIntercept( chain, false ); + } + } catch (Exception e) { + response.body().close(); + throw e; } } return response; diff --git a/src/main/resources/handlebars/Java/libraries/retrofit2/auth/OAuth.mustache b/src/main/resources/handlebars/Java/libraries/retrofit2/auth/OAuth.mustache index e3b3727cd8..59c0984ae2 100644 --- a/src/main/resources/handlebars/Java/libraries/retrofit2/auth/OAuth.mustache +++ b/src/main/resources/handlebars/Java/libraries/retrofit2/auth/OAuth.mustache @@ -113,8 +113,15 @@ public class OAuth implements Interceptor { // 401/403 most likely indicates that access token has expired. Unless it happens two times in a row. if ( response != null && (response.code() == HTTP_UNAUTHORIZED || response.code() == HTTP_FORBIDDEN) && updateTokenAndRetryOnAuthorizationFailure ) { - if (updateAccessToken(requestAccessToken)) { - return retryingIntercept( chain, false ); + if ( response != null && (response.code() == HTTP_UNAUTHORIZED || response.code() == HTTP_FORBIDDEN) && updateTokenAndRetryOnAuthorizationFailure ) { + try { + if (updateAccessToken(requestAccessToken)) { + response.body().close(); + return retryingIntercept( chain, false ); + } + } catch (Exception e) { + response.body().close(); + throw e; } } return response;