Skip to content

Get a custom response error #1233

Answered by TkDodo
apenab asked this question in Q&A
Discussion options

You must be logged in to vote

Errors are generic in react-query because every promise from a fetch / mutation function can throw with, well, anything literally in javascript, so there is no way to tell. I would just do a custom hook:

const useMyMutation = () => {
    const { error, ...mutate } = useMutation(async () => ...)

    return { ...mutate, error: error?.response.data }
}

or something similar.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by apenab
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants