cannot catch error from fetch call when used a malformed URL
See original GitHub issueIs this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
Environment: OS: Windows 10 Node: 6.12.3 Yarn: Not Found npm: 3.10.10 Watchman: Not Found Xcode: N/A Android Studio: Version 3.0.0.0 AI-171.4443003
Packages: (wanted => installed) react: 16.2.0 => 16.2.0 react-native: 0.53.3 => 0.53.3
Target Platform: Android 6 Emulator (From the Getting Started howto)
Steps to Reproduce
Cannot catch the fetch call when used a malformed url.
- Call fetch() with a malformed url like ‘asd’ or ‘https:😕/facebook.github.io’
- try to catch with ‘.catch’ when called as promise or try/catch within async/await
Expected Behavior
catch should be executed
Actual Behavior
red screen shows up with “unexpected url: [URL USED WITHIN THE CALL]”
Reproducible Demo
async asyncFetch(url) {
try {
console.log('DEBUG - START FETCHING');
const response = await fetch(url);
console.log('DEBUG - END FETCHING');
const xml = await response.text();
const json = xml2json.parse(xml);
return { data: json };
} catch (error) {
console.log('DEBUG - START ERROR: ' + error.message);
throw error;
}
}
const url = 'httasd:afdasdfads';
this.asyncFetch(url)
.catch(err => {
console.log('DEBUG - Error: ' + err.message);
})
Actual console output is: DEBUG - START FETCHING
Note: Same issue like #17843
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:9
Top Results From Across the Web
Fetch response malformed - javascript - Stack Overflow
The issue is basically that the fetch response object is not correct. Pictures to clarify the issue are below as it is hard...
Read more >Handling Failed HTTP Responses With fetch() - TJ VanToll
Per MDN, the fetch() API only rejects a promise when a “network error is encountered, although this usually means permissions issues or similar....
Read more >Handling operation errors - Apollo GraphQL Docs
Apollo Client can encounter a variety of errors when executing operations on your GraphQL server. Apollo Client helps you handle these errors according...
Read more >HTTP status and error codes for JSON | Cloud Storage
The following document provides reference information about the status codes and error messages that are used in the Cloud Storage JSON API.
Read more >Guide to Spring Boot REST API Error Handling - Toptal
Using JERSY(@path attribute), not able to handle exceptions. Not using @requestmapping and RestExceptionHandler not handling this. Can you please help on this.
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
fetch has been having this very bad problem for some time now, crashing apps in production whenever something it doesn’t like happen. At this point, I’m looking for good alternatives 😦
This issue has been inactive for a very long time, closing. There are newer and more active issues on this subject.