-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'unsupported BodyInit type' error is uncatchable #2538
Comments
This seems like an issue that is better suited for https://github.com/github/fetch - this is the polyfill that we're using in React Native 😄 Could you repost it there? If it turns out to be a problem with React Native's XMLHttpRequest implementation we can look into that further. That said, I tried this with some obviously invalid thing - fetching a url that didn't exist, and it didn't go into either of the catch blocks in Chrome.
|
It's not going into either because it accepts the body init type. That was the second part of my question. Is an Object an officially supported body init type? Because chrome does accept it. 😃 Try this: try {
fetch('/lololol', {
method: 'POST',
body: {
username: 'a',
password: 'b'
}
})
.then(function(json) {
console.log(json)
})
.catch(function(error) {
// not called
console.error("INSIDE")
})
} catch (e) {
// called
console.error("OUTSIDE")
} Also I'm not completely sure if opening this at github/fetch would help here, since I don't know if fixes from there will be back-ported to react-native's version of fetch. Github made it clear that they are not interested in making the polyfill work anywhere except in a browsers. Also the fetch version in react-native was already patched to work and probably keeps going to get patched. |
As per https://github.com/github/fetch, to post JSON you need to set correct headers and stringify json before putting in
|
Thanks @sgaurav that resolved my issue. Not familiar with the fetch api, and I had forgotten to set headers |
Initializing a fetch with an incorrect body type throws an error instead rejecting the promise:
Is that standard behaviour? Also why wouldn't the polyfill accept it? Chrome does accept it.
The text was updated successfully, but these errors were encountered: