浏览代码

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

Artem Emelyanov 4 年前
父节点
当前提交
4ff2d8a293
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5
    1
      android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

+ 5
- 1
android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java 查看文件

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
                         }