Possible Unhandled Promise Rejection (id: 0): Error at handleReject
Hello,
I have an android app and a backend written in node.js.
For the app I use redux + redux-promise-middleware.
I have the following action:
export const createUser = (data) => ({
type: types.CREATE_USER,
payload: new Promise( (resolve, reject) => API.createUser(data, resolve, reject) )
})
And the API where I reject the promise if json has an error message:
export const createUser = (data, resolve, reject) =>
API.post('user', data)
.then( res => res.json() )
.then( json => json.error ? reject(json) : resolve(json) )
.catch( e => reject(e) )
So after I dispatch the createUser action I recive the following YellowBox warning:
Possible Unhandled Promise Rejection (id: 0): Error at handleReject
The error is not showing if in .then I do like this:
.then( json => resolve(json) )
› react-native -v
react-native-cli: 0.2.0
react-native: 0.31.0
Can someone explain why this is happening?
This is because you are wrapping the API promise within in promise. In the catch of the API promise you reject the wrapping promise but nothing is catching that promise which prompts the warning. I would recommend asking over at redux-promise-middleware how to handle as this is not an issue with React Native itself. Closing this issue.
@facebook-github-bot close
@rmevans9 tells me to close this issue. If you think it should still be opened let us know why.