Replies: 5 comments 7 replies
-
it works for me: https://codesandbox.io/s/compassionate-frost-4zoh1?file=/pages/index.js do you have a codesandbox that shows your issue please? |
Beta Was this translation helpful? Give feedback.
-
Instead of throwing an error you can return a promise in which you call reject:
|
Beta Was this translation helpful? Give feedback.
-
Having the same issue in react app, getting "Uncaught runtime errors" Doing it the same as in docs (https://tanstack.com/query/v5/docs/framework/react/guides/mutations) export const useSubscribeMutation = () =>
useMutation({
mutationFn: (email: string) => {
return axios.post(
new URL(`subscribe`, process.env.REACT_APP_API_BASE_URL).toString(),
{ email }
);
},
}); |
Beta Was this translation helpful? Give feedback.
-
I am also facing this problem. I guess I wrongly assumed |
Beta Was this translation helpful? Give feedback.
-
I know this is really old but I'm having a similar issue: I have this big mutation that composes other mutations. export default function useCreatePrediction() {
const router = useRouter();
const { toast } = useToast();
const form = usePredictionForm();
const findOrCreateCase = useFindOrCreateCase();
const runPrediction = useRunPrediction();
return useMutation({
mutationFn: async () => {
const result = schema.safeParse(form.getValues());
if (!result.success) throw new Error("Invalid form data");
try {
const newCase = await findOrCreateCase.mutateAsync(result.data);
if (!newCase) return;
await runPrediction.mutateAsync({
caseId: newCase.id,
values: result.data,
});
void trackOnClient().predictionCreated(form.trackingValues());
} catch {
throw new Error("Error creating prediction");
}
},
onSuccess: () => router.push(Routes.success),
onError: () =>
toast({
variant: "error",
description:
"There was an error creating the prediction. Please try again.",
}),
});
} |
Beta Was this translation helpful? Give feedback.
-
When I throw an error inside a mutation handler I still get an uncaught error.
My code looks like this:
I would expect the error to be caught by react-query. What am I doing wrong here?
Beta Was this translation helpful? Give feedback.
All reactions