-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
How to catch mutation errors from the server #1496
Comments
@webular I think it might not be possible at the moment. It should be pretty easy to fix with a PR though, I think. cc @cesarsolorzano do you think it's feasible? |
@webular can you try this with If that doesn't work, please print Thanks! |
If your server returns something different than 200 response (like a 401 Unauthorized), we found the error buried in "networkErrors". const getNetworkErrors = error => error.networkError.response.json().then(e => e.errors.map(e => e.message).join(','))
return auth(values) //<— this is a mutation
.then(({data}) => {
loginThenRedirect(data); // <--- log user in
})
.catch(error => {
if (error.networkError) {
getNetworkErrors(error).then(console.log)
} else {
console.log(error.message)
}
}); We use yarn add stringify to discover the structure of errors. |
@helfer Ok that worked out. I was able to get the error object by doing not sure if there is a better way to turn the string into an object but this works for me. Thank you all for the help! |
When I catch the error from a mutation like this, .catch((e) => { console.log(e) }) The following message is logged to the console,
So I got the impression that this issue was still occurring. When I inspected the object more closely, like this, .catch((e) => { console.log(e.graphQLErrors) }) It logged an array of error objects. So the problem was my expectations, not the object itself. Just putting this here for posterity, in case anyone else is caught off-guard by this behaviour. |
Got the same, and it doesn't seem to be documented |
Is it a good idea to catch user-specific errors like "wrong email or password", using apollo-errors? I'm trying to figure out how to update the store on a catch. |
Using:
Is there a nice way to get just the message? Other than doing |
@gorjanz Have you tried |
@tgdn yes, it prints an array with objects, with one of the keys being the message I printed above. |
@gorjanz I'm having problems with graphql-server-express , so this is outdated ? i have some problems with catch errors with that ; must I migrate to apollo-server-express ? |
Am experiencing a similar issue with graphql-java backend. Cannot access the errors within the catch. e.graphQLErrors is undefined. Maybe its the response sent back by the server? Does anybody know what that data is supposed to look like? |
Hope this helps someone: |
This just saved my day. Thank you @TheRusskiy |
For me, It is because of some of my packages relays on node.js which clearly not on mobile. |
I’ve got a question about error handling client side.
My server returns this on validation error:
I’d like to get access to the validation errors using apollo-client mutation - something like this:
But
mutationErrors
get swallowed up and only show a stringError: GraphQL error: An authentication error has occurred…
Is there a way to get the contents of the server error so I can display it client side?
The text was updated successfully, but these errors were encountered: