react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Possible Unhandled Promise Rejection (id: 0): Error at handleReject

Open indie314 opened this issue 10 years ago • 3 comments

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?

indie314 avatar Sep 14 '16 08:09 indie314

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.

rmevans9 avatar Sep 14 '16 11:09 rmevans9

@facebook-github-bot close

rmevans9 avatar Sep 14 '16 11:09 rmevans9

@rmevans9 tells me to close this issue. If you think it should still be opened let us know why.

ghost avatar Sep 14 '16 11:09 ghost