Reputation: 481
I'm getting an unhandled promise rejection error when I use useMutation
with react native. Here's the code producing the issue:
const [createUser, { error, loading }] = useMutation(CREATE_USER_MUTATION);
Anytime my graphql server returns an error to the client I get an unhandled promise rejection error (screenshot below). I'm able to make it go away by adding an error handler like so, but it seems like a hack. Any thoughts? Am I doing something wrong or is this something that should be addressed by the apollo folks?
const [createUser, { error, loading }] = useMutation(CREATE_USER_MUTATION, {
onError: () => {}
});
Upvotes: 6
Views: 4060
Reputation: 701
const [createUser, { data, loading }] = useMutation(CREATE_USER_MUTATION, {
onError: (err) => {
setError(err);
}
});
With this we can access data with loading and proper error handling.
Upvotes: 0
Reputation: 178
Your createUser
mutation is a promise you should handle error inside try catch
block, or in upper scope inside apollo-link-error onError
method.
Upvotes: 2