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

Trouble handling 500 Internal Server Error Response #378

Open
liv002 opened this issue Aug 26, 2024 · 2 comments
Open

Trouble handling 500 Internal Server Error Response #378

liv002 opened this issue Aug 26, 2024 · 2 comments

Comments

@liv002
Copy link

liv002 commented Aug 26, 2024

Specs

  • React Native v.0.72.6
  • React Native Blob Util v.0.19.11

Issue

In our project, it seems like if the .fetch call receives a status 404, 401 etc. it goes to the .catch as expected.

Meanwhile, if the .fetch call's response is a 500 Internal Server Error, it does not move on at all. It neither goes the the .then bracket, nor the .catch. See code snippet for illustration

const configOptions: ReactNativeBlobUtilConfig =
            Platform.OS === 'ios'
                ? {
                      fileCache: true,
                      appendExt: '.pdf',
                      path: <path>
                  }
                : //android
                  {
                      addAndroidDownloads: {
                          useDownloadManager: true,
                          notification: true,
                          mime: 'application/pdf',
                      },
                  };

ReactNativeBlobUtil.config(configOptions)
            .fetch(
                'GET',
                `url....`,
                {
                    headers...
                }
            )
            .then((res) => {
                console.log('This does not happen when 500 response');
            })
            .catch((e) => {
                console.log('this does not happen when 500 response');
            });

We tried multiple setups, but could never get it to work. The only way to handle it that we found was to simply cancel the request after a set time.

        // Cancel request after 3 minutes in case of internal server error
        setTimeout(() => {
            task.cancel();
        }, 1000 * 60 * 3);
@liv002 liv002 changed the title Trouble handling 500 Internal Server Error Trouble handling 500 Internal Server Error Response Aug 26, 2024
@liv002
Copy link
Author

liv002 commented Aug 27, 2024

Edit:
After further testing, this seems to be the case specifically for running on android, as iOS seems to be handling the response as expected.

@luisjdtt
Copy link

luisjdtt commented Sep 13, 2024

Same case for me! Is the timeout the only solution to this? I don't like that approach tbh. It just hangs infinetly, no log on javascript side or something like that

Info:
react-native: 0.73.9
react-native-blob-util: 0.9.11
Tested on Android 10 to 14.

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

3 participants
@liv002 @luisjdtt and others