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

when using fetch, axios, etc.catch doesn't handle the error, instead your app crashes #24249

Closed
blueturtle13g opened this issue Apr 1, 2019 · 8 comments
Labels
Bug 🌐Networking Related to a networking API. Platform: Android Android applications. Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.

Comments

@blueturtle13g
Copy link

blueturtle13g commented Apr 1, 2019

🐛 Bug Report

To make sure that our request will be successful, first, we check the internet connection then send our request.
This approach was fine until I faced this issue: consider a situation in which access to a server for some countries is blocked.
So, although the internet connection was ok, each time I was getting network request failed error and my app was just crashing.
Note that this issue is not limited to this problem, it also happens when your internet speed is low, etc.
So, What is the point of catch!? if it doesn't catch the error!?

To Reproduce

react-native init myApp
sending a request to an endpoint which is blocked for your IP.

Expected Behavior

The expected behavior is that, when the connection can't be made, catch gets the error and I can inform the user to use a VPN or leave the app because they are in an embargoed country!

Code Example

NetInfo.isConnected.fetch().then(async isConnected=> {
  if(isConnected){
    try {
       let result = await fetch(MY_REMOTE_SERVER);
       console.log("result: ", result)
    } catch (error) {
       console.error("error: ", error);
    }
  }
  else ToastAndroid.show('No internet', ToastAndroid.SHORT);
});

Environment

React Native Environment Info:
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
Memory: 4.09 GB / 7.90 GB
Binaries:
Yarn: 1.12.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.2.0.0 AI-181.5540.7.32.5056338.

@react-native-bot react-native-bot added Platform: iOS iOS applications. 🌐Networking Related to a networking API. labels Apr 1, 2019
@dulmandakh dulmandakh added Platform: Android Android applications. and removed Platform: iOS iOS applications. labels Apr 2, 2019
@dulmandakh
Copy link
Contributor

what is your React Native version?

@react-native-bot react-native-bot added the Platform: iOS iOS applications. label Apr 2, 2019
@blueturtle13g
Copy link
Author

what is your React Native version?

"react-native": "0.59.1".

@eliabiraschi
Copy link

I'm having the same issue on both Android and iOS, but with a different library ("react-native-firebase": "^5.2.3"). I don't know if the two things are related, here the issue on the lib tracker invertase/react-native-firebase#1993.

"react-native": "0.59.3"

@JKCooper2
Copy link

Is it crashing in debug or release mode? In debug mode a console.error will throw up a red screen, but won't cause a crash in release

@blueturtle13g
Copy link
Author

@JKCooper2 yes you right, but until you change your app to release mode, you won't understand it, on the other hand, it bothers a lot when you're in debug mode because you get the red screen and your app restart. If catch could get the error, it would be great. thanks

@blueturtle13g
Copy link
Author

Is it crashing in debug or release mode? In debug mode a console.error will throw up a red screen, but won't cause a crash in release

oh, I'm sorry you right. I should replace console.error with console.log and it won't crash anymore

@Salakar
Copy link
Contributor

Salakar commented Jun 27, 2019

oh, I'm sorry you right. I should replace console.error with console.log and it won't crash anymore

👋 closing this issue now as I believe this is resolved, if not please let me know.

@Salakar Salakar closed this as completed Jun 27, 2019
@Alfredo-Delgado
Copy link

I wish "Hey, BTW, console.error intentionally crashes your app in development." were more prominently documented and/or configurable.

@facebook facebook locked as resolved and limited conversation to collaborators Jun 27, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jun 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug 🌐Networking Related to a networking API. Platform: Android Android applications. Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

8 participants