RonRadtke/react-native-blob-util

response.json() is throwing an Error in Android saying No such file or directory

KManiKumarReddy opened this issue · 2 comments

Hi

We've upgraded from version 1.19.1 to 1.19.8 and started seeing this issue.

when we call response.json() it goes to the catch block with the Error:

{ nativeStackAndroid: [],
  userInfo: null,
  message: 'No such file \'/storage/emulated/0/Download/XXXXXXXnt_21480367849_190729457.pdf\'; /storage/emulated/0/Download/XXXXXXnt_21480367849_190729457.pdf: open failed: ENOENT (No such file or directory)',
  code: 'ENOENT' }

Our code looks something like this:

  const { LegacyDownloadDir: DownloadDir } = ReactNativeBlobUtil.fs.dirs;
  const path = `${DownloadDir}/${fileName}_${format(Date.now(), 'HHmmssSSS')}.pdf`;
  const configAndroid = {
    fileCache: true,
    path,
    timeout: Config.NETWORK_TIMEOUT(),
  };

 ReactNativeBlobUtil.config(configAndroid)
      .fetch('POST', url, {
        'Content-Type': 'application/json',
        'x-requested-with': 'XMLHttpRequest',
        Accept: 'application/pdf, application/pdf'},
        options.payload && JSON.stringify(options.payload))
      .then(res => {
        if (res.respInfo.status === 200) {
              // some business logic working well, if we use .json() here it breaks as well
        } else {
          res
            .json()  // this throws an error and goes to catch block
            .then(error => onError(error, res))
            .catch(error => {
              onError(error, res);   // this catch block is hit
            });
          ReactNativeBlobUtil.fs.unlink(res.path());
        }
      })
      .catch(error => {
        onError(error);
      });

It is working well in iOS, the difference that we notice is fileCache:true in config which is not available in iOS

Does it work fine on Android without the file cache?