Browse Source

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

Artem Emelyanov 3 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
                     if (responseBody != null) {
600
                     if (responseBody != null) {
601
                         String responseBodyString = null;
601
                         String responseBodyString = null;
602
                         try {
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
                         } catch(IOException exception) {
608
                         } catch(IOException exception) {
605
                             exception.printStackTrace();
609
                             exception.printStackTrace();
606
                         }
610
                         }