In my api function, I'm returning success => false, error=>error_1 I'm using useMutation to validate some data
export const validateSomeData = async (code, data, res) => {
try{
const response = await axios.post(`test/data/${code}`, {data});
if(response.data.success){
return response.data.coupon;
}
// add code here
}catch(e){
// and here
}
};
I want to return error so that react query error and isError will be true I tried to
throw new Error(response.data.error);
but error was filled with error_1 in test/data and the whole error stack I'm only interested in error_1 for context here is my useMutation hook
export const useDataValidation = () => {
const { data, error, isError, isPending, mutateAsync } = useMutation({
mutationKey: ["test"],
mutationFn: (code, data) => validateSomeData (code, data),
});
return { data: data ?? {}, isPending, error, isError, validateData: mutateAsync}
};