Skip to content
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

change the way to get message from onError option the useMutation hook #4004

Open
wants to merge 1 commit into
base: source
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/content/8/es/part8b.md
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,20 @@ const PersonForm = ({ setError }) => {
refetchQueries: [ {query: ALL_PERSONS } ],
// highlight-start
onError: (error) => {
const errors = error.graphQLErrors[0].extensions.error.errors
//To access the Apollo error message, for some reason this way it doesn't work, changing the code this way I was able to access the error message, and I was able to continue with the class without problems
// FROM THIS:
/* const errors = error.graphQLErrors[0].extensions.error.errors
const messages = Object.values(errors).map(e => e.message).join('\n')
setError(messages)
}
*/
// TO THIS:
const message = error.graphQLErrors[0].message
if (message) {
setError(message)
} else {
setError('something went wrong')
}
}
// highlight-end
})

Expand Down