question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Download large file with a weak network connection: resolves with status 200 when the file is not fully loaded

See original GitHub issue

Versions

"react": "16.6.1",
"react-native": "0.57.5",
"rn-fetch-blob": "^0.10.13"

Problem I download the file to the device. When the Internet connection is weak or the connection is broken, the file download stops. But instead of an error, RNFetchBlob’s promise successfully resolves with 200 status code and has the path to the broken file.

Actual Behavior: RNFetchBlob’s promise successfully resolves with 200 status code when file was not fully downloaded

Expected Behavior: If the connection is broken, RNFetchBlob’s promise resolves with an error and I can catch the error in the .catch block.

Code

      return new Promise((resolve, reject) => {
            RNFetchBlob
                .config({
                    // add this option that makes response data to be stored as a file,
                    // this is much more performant.
                    fileCache : true,
                    session : 'init',
                    path : path,
                    trusty : true
                })
                .fetch('get', url, {})
                .progress((received, total) => {
                    if (OfflineMapDownloadService.isDBDownloading) {
                        this.progressCallback(received/total);
                    }
                })
                .then((res) => {
                    let status = res.info().status;
                    if(status === 200) {
                        resolve(res.path());
                    } else {
                        console.log(res);
                        reject(new Error('Invalid RN-blob status ' + status));
                    }
                })
                .catch((errorMessage, statusCode) => {
                    console.log(errorMessage);
                    Sentry.captureException(new Error(errorMessage));
                    reject(errorMessage);
                });
        });

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12

github_iconTop GitHub Comments

5reactions
olegmilancommented, Oct 8, 2019

Any updates on this issue? I’m still seeing this issue on both platforms (Android and IOS). To reproduce it, I just need to turn off wifi/4g during download and it can be a small file(not necessary a big file) like image with ~1mb size

      "version": "0.10.16",
      "resolved": "https://registry.npmjs.org/rn-fetch-blob/-/rn-fetch-blob-0.10.16.tgz",
      "integrity": "sha512-hZV+nF0HK4CWmspXGMw7/G8Q8qugpS/wbKiNLsFpdBZR8XYzjFZNvBWgGyC0F5JWQn3sjmK2w/FJjBlwdQWNQg==",
      "requires": {
        "base-64": "0.1.0",
        "glob": "7.0.6"
      },
2reactions
JofBigHealthcommented, Apr 24, 2019

Note also that progress won’t always finish with totalBytes === downloadedBytes with iOS either. However, iOS doesn’t seem to have this exact problem when attempted to resume; if the connection fails to resume the native (OS) code will timeout and RBFB will report that error.

In conclusion; I don’t recommend comparing downloaded to total bytes for either platform without fixing the native code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix file download errors - Google Chrome Help
This error means that there's not enough space on your computer to download the file. To fix the error: Delete some files from...
Read more >
How to deliver big files in ASP.NET Response? - Stack Overflow
This results in very slow start of file, as user downloads and even progress bar does not appear till few seconds, typically 3...
Read more >
A Complete Guide and List of HTTP Status Codes
A complete list of HTTP status codes with explaination of what they are, why they occur and what you can do to fix...
Read more >
Avoiding the Top 10 NGINX Configuration Mistakes
Errors include insufficient file descriptors per worker, disabling proxy buffering, and not using upstream groups and keepalive connections.
Read more >
HTTP Status Codes List | HTTP Error Codes Explained
Status code 102 is an interim response code, telling the client that the server has accepted the full request, but has not completed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found