Skip to content

Commit 6806822

Browse files
Ron RadtkeRon Radtke
Ron Radtke
authored and
Ron Radtke
committed
fixes #64
1 parent ece3401 commit 6806822

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,9 @@ public Response intercept(Chain chain) throws IOException {
398398
clientBuilder.addInterceptor(new Interceptor() {
399399
@Override
400400
public Response intercept(@NonNull Chain chain) throws IOException {
401+
Response originalResponse = null;
401402
try {
402-
Response originalResponse = chain.proceed(req);
403+
originalResponse = chain.proceed(req);
403404
ResponseBody extended;
404405
switch (responseType) {
405406
case KeepInMemory:
@@ -428,12 +429,21 @@ public Response intercept(@NonNull Chain chain) throws IOException {
428429
return originalResponse.newBuilder().body(extended).build();
429430
} catch (SocketException e) {
430431
timeout = true;
432+
if (originalResponse != null) {
433+
originalResponse.close();
434+
}
431435
} catch (SocketTimeoutException e) {
432436
timeout = true;
437+
if (originalResponse != null) {
438+
originalResponse.close();
439+
}
433440
//ReactNativeBlobUtilUtils.emitWarningEvent("ReactNativeBlobUtil error when sending request : " + e.getLocalizedMessage());
434441
} catch (Exception ex) {
435-
442+
if (originalResponse != null) {
443+
originalResponse.close();
444+
}
436445
}
446+
437447
return chain.proceed(chain.request());
438448
}
439449
});

0 commit comments

Comments
 (0)