Mutation does not correctly pick up an error when it's run for the first time #3111
-
Hi, first of all, thank you for this awesome library. If I run a mutation that throws an error, it doesn't get picked up the first time around. (Well it does, but only somewhere) Also if I run the mutation with correct data and get a success, I still need to have a failed mutation before it starts working properly. So my guess is it's getting the data of the previous error instead of it's own error? What am I doing wrong? //This is the mutation hook
export const useAddWorkspaceUser = () => {
return useMutation(
(data: { email: string; workspaceId: number }) => {
return defaultMutationFn(`workspace/${data.workspaceId}/user`, { data: { email: data.email } });
},
{
onSuccess: async (data, vars) => {
queryClient.setQueryData([`workspace/${vars.workspaceId}`, vars.workspaceId], (old: any) => ({
...old,
users: data.users,
}));
store.dispatch(showNotification({ message: "User successfully Added", severity: "success" }));
},
},
);
}; export const defaultMutationFn = async (endpoint: string, options?: AxiosRequestConfig) => {
const { data } = await axios({
url: API_URL + "/" + endpoint,
method: options?.method ?? "POST",
...options,
...defaultOptions,
});
return data;
};
const mutationCache = new MutationCache({
onError: (err: any) => {
handleErrors(err.response);
},
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
that sounds weird. can you reproduce that in a codesandbox ? |
Beta Was this translation helpful? Give feedback.
that sounds weird. can you reproduce that in a codesandbox ?