Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KManiKumarReddy opened this issue Apr 5, 2024 · 2 comments

Comments

@KManiKumarReddy
Copy link

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

@RonRadtke
Copy link
Owner

Does it work fine on Android without the file cache?

@KManiKumarReddy
Copy link
Author

yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants