react-native-blob-util icon indicating copy to clipboard operation
react-native-blob-util copied to clipboard

Download fails with `201` and skips `.then` block, contrary to Readme.md

Open latobibor opened this issue 2 years ago • 0 comments

Hi everyone!

First of all thank you very much for upgrading this package to latest react-native versions. During working with the package we have encountered the following problem:

console.log(1);

const res = await RNFetchBlob.config({
  fileCache: true,
  addAndroidDownloads: {
    useDownloadManager: true,
    notification: true,
    path: `${RNFetchBlob.fs.dirs.DownloadDir}/some_path`,
   },
})
      .fetch('GET', my-url, { ...someHeaders })
      .then(response => {
        console.log(2, response.info().status);
        return response;
      });

console.log(3, res.info().status);

According to the documentation if fetch returns something other than 200 we can handle it in the then block (or by awaiting it). However whatever I have tried it rejects the promise and the then block never runs and obviously neither does the last console.log.

I could change my endpoint to return 200 instead of 201 and the download was successful. Naturally I would just correct the endpoint (a GET endpoint should not return 201 anyways!), but I realized that the control flow for this case seems compared to the readme.

Oh and the versions: react-native-blob-util: 0.19.0 react-native: 0.69.10

latobibor avatar Aug 11 '23 19:08 latobibor