how to handle network request failed error?
See original GitHub issueI have a form and want to send it to a server and get a response so I wrote this:
submitForm = async () => {
fetch("www.somewhere.com", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(some_data)
})
.then((response) => response.json())
.then((responseJson) => {
// do something
})
.catch((error) => {
this.setState({server_error: "request failed try again."});
});
};
But It seems that my catch doesn’t work correctly because if the request fails I get an error from react native like this:
TypeError: Network request failed at XMLHttpRequest.xhr.onerror (C:\Archive\code\current\native\melcom\node_modules\react-native\Libraries\vendor\core\whatwg-fetch.js:504)
Note that I’m not struggling with http or https, I just want to provide a nice error to the user if the request fails due to the internet connection, wrong API, etc. instead of getting react native error.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:18
Top Results From Across the Web
React Native fetch() Network Request Failed - Stack Overflow
1) To find out the exact error in the logs, I first enabled 'Debug JS Remotely' using Cmd + M on the app...
Read more >HTTP Fetch fails with "TypeError: Network request ... - GitHub
Using fetch to get/post on a HTTPS web server which is using a valid and trusted but not public CA. Using Chrome and...
Read more >How to solve 'TypeError: Network request failed' in React ...
two thing : 1. add android:usesCleartextTraffic="true" in your Android manifest android/app/src/main/AndroidManifest.xml2.
Read more >How to Fix Instagram Error Network Request Failed Problem ...
Instagram #Network #Request #FailedIn this video i will show you How to Fix Fix Instagram Error Network Request Failed Problem in Android ...
Read more >Network Request Failed/Network Error in React Native using ...
It's just that simple! Start your app as usual but don't forget to give an IP address and a port, this will help...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
error.message this.state.error:error.message
Have you found a solution for this? I am having the same error.