react-native: fetch("aaa") has incorrect behavior

Unable to catch error thrown from fetch with invalid url. Instead I get a message about “unexpected url”.

  • Provide a minimal code snippet / rnplay example that reproduces the bug.
try {
   fetch("aaa");
} catch (ex) { }
  • Provide screenshots where appropriate image
  • What’s the version of React Native you’re using? 0.24.1
  • Does this occur on iOS, Android or both? Android
  • Are you using Mac, Linux or Windows? OS X

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 5
  • Comments: 20 (15 by maintainers)

Commits related to this issue

Most upvoted comments

I think we should always do 2 and sometimes do 1 as well. That is, convert all native failures to promise rejections, but also do extra validation in JS when we think we can provide better error messages closer to the source of the error.

Re-open it, please.

@lacker I think it’s different. In the browser console you call fetch('aaa')) which was automatically converted to fetch('https://www.google.com/aaa'), the request url is valid. But in react-native, when we call fetch we should pass an specific valid url, but 'aaa' is invalid.