Description
🐛 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.