0

I am developing a react native project for mobile applications. The app works fine in debug mode but doesn't work properly after I release the app with CLI. I think the API request part in Promise.all() inside the code below has an issue in release mode. If anyone has faced similar problems before, then please let me know a suitable solution.

useEffect(() => {
    getUserInfo('sdf').then(d => {
      const userId = 'sdf';
      Promise.all([
        fetchPortfolio(userId, 'coin'),
        fetchPortfolio(userId, 'idea'),
        getCryptoNews('stocks'),
      ])
        .then(values => {
          dispatch(setCryptoPortfolio(values[0].items ? values[0].items : []));
          dispatch(setIdeaPortfolio(values[1].items ? values[1].items : []));
          setNewsList(values[2].slice(0, 3));
          setLoading(false);
        })
        .catch(err => {
          console.log(err);
          setLoading(false);
        });
    });
}, []);

It executes the code inside .catch() block of the code in release mode.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 2
    What is the error you are seeing? – tomerpacific Nov 17 '21 at 10:36
  • The app crashes immediately. I think it doesn't get the response via API, it goes directly to catch() block of exception handling. – lucky brand Nov 17 '21 at 10:38
  • 1
    `Promise.all()` rejects as soon as any of the promises passed to it rejects. I assume that one of your network requests fails. As you are probably using different urls for the requests in debug and in release mode, I'd recommend you to check the release urls. – swift-lynx Nov 17 '21 at 10:40
  • 2
    If you have a try/catch block, then how does your application crash? Also, you are printing a log there... – tomerpacific Nov 17 '21 at 10:42
  • The first two requests are sent to fetch the data from firestore, and the third one is from third API. They use the same urls with ones in debug mode. – lucky brand Nov 17 '21 at 10:43
  • In the debug mode, it works well – lucky brand Nov 17 '21 at 10:45
  • You need to look at what the `err` it is catching. One possible failure is that `values[2]` is not an array, but this is just a speculation. – tromgy Nov 17 '21 at 10:51
  • The third request returns [] when axios request fails. – lucky brand Nov 17 '21 at 11:52
  • The third request fetches data from `http://123.123.123.123: 80/index.php?q=Tesla` with axios. Is that a cause of reject? – lucky brand Nov 17 '21 at 12:15
  • Nothing in the code shown appears to be sensitive to debug vs. release mode. Why are you ignoring the requests to include the actual error message in your post? – jarmod Jun 19 '23 at 13:25

1 Answers1

0

I was facing the same issue in my react native project, where a number of requests were being triggered in Promise.all() and it wasn't catching any error instead it just getting crashed

After hours what i found is, there were api requests having https and http, http requests were working fine in debug mode but not in release mode

Then i simply allowed http requests using this solution: https://github.com/facebook/react-native/issues/24408#issuecomment-490368508

After applying this, every thing got fine

Shoaib Virk
  • 81
  • 1
  • 4