-
Hi. Sorry for this noob question but I can't figure it out. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 13 replies
-
It depends on what you are using for data fetching, react-query is completely agnostic in that regard.
|
Beta Was this translation helpful? Give feedback.
-
For those struggling with Axios: You can configure a global error handler using Axios response interceptors:
Warning: If you use a toast component, every single error are going to be shown |
Beta Was this translation helpful? Give feedback.
-
Is there a way to modify the error before it is stored in the new Promise((_, reject) => reject("Error!"))
.catch((e) => {
if (e instanceof Error) throw e;
if (typeof e === 'string') throw new Error(e);
throw new Error('Unknown error');
}) My expectation is that I can just pass my error mutation in the Full example: const mutation = useMutation({
mutationFn: async () => new Promise((_, reject) => reject("Error!")),
onError: e => {
if (e instanceof Error) throw e;
if (typeof e === 'string') throw new Error(e);
throw new Error('Unknown error');
},
});
mutation.error.message // should be 'Unknown error', instead I get nothing, stuck on loading |
Beta Was this translation helpful? Give feedback.
It depends on what you are using for data fetching, react-query is completely agnostic in that regard.
axios
, it will give you anAxiosError
which has the json body somewhere inerror.response.data
or so.fetch
, you have to json parse the body yourselves viaerror.response.json()
.