Browse Source

check if buffer data and content exists before trying get data from source

Artem Emelyanov 4 years ago
parent
commit
4ff2d8a293
1 changed files with 5 additions and 1 deletions
  1. 5
    1
      android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

+ 5
- 1
android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java View File

@@ -600,7 +600,11 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
600 600
                     if (responseBody != null) {
601 601
                         String responseBodyString = null;
602 602
                         try {
603
-                            responseBodyString = responseBody.string();
603
+                            boolean isBufferDataExists = responseBody.source().buffer().size() > 0;
604
+                            boolean isContentExists = responseBody.contentLength() > 0;
605
+                            if (isBufferDataExists && isContentExists) {
606
+                                responseBodyString = responseBody.string();
607
+                            }
604 608
                         } catch(IOException exception) {
605 609
                             exception.printStackTrace();
606 610
                         }