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
- 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
- Catch exception and report it when making a network request with invalid URL on Android Currently if you invoke `fetch()` with an invalid URL ("aaa" for example) you cannot catch the error in javascr... — committed to jcurtis/react-native by jcurtis 6 years ago
- Catch exception and report it when making a network request with invalid URL on Android Summary: Currently if you invoke `fetch()` with an invalid URL ("aaa" for example) you cannot catch the error i... — committed to facebook/react-native by jcurtis 6 years ago
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 tofetch('https://www.google.com/aaa')
, the request url is valid. But in react-native, when we callfetch
we should pass an specific valid url, but'aaa'
is invalid.