我正在使用Reaction Query作为数据处理程序.我对本机的react 是新的,对查询的react 也是新的.
现在我真的不明白为什么onError回调不能处理我的错误.错误回调由错误触发,错误仍然转到函数中的Catch处理程序(这是我不想要的).
我有以下设置/ struct :
API层中的Axios.不试着接球. UseMutation Setup(使用Mutation Setup),其中mutuationFn指向"axios API请求". ClickHandler触发一个进行Mutations 的函数.
const mutation = useMutation({
mutationFn: (req: TimeReportRequest) => {
return updateTimeReport(timeReport?.id!, req);
},
onSuccess: (data) => {
queryClient.invalidateQueries({ queryKey: ['timeReports'] });
},
onError: (error) => {
console.log('Im the error and i should not go further');
errorMessageHandler(error);
},
});
const onSubmitTimeReport = () => {
try {
if (!timeReport) return;
const req: TimeReportRequest = {
...
};
mutation.mutate(req);
} catch (error) {
console.log("im will recieve the error. But i shouldn't?. Error is not handled as a normal try-catch")
}
};
主要问题是错误没有得到正确的处理.如果我删除了REACT查询,直接使用api-layer(axios方法)并try 捕获,那么一切都会按预期进行.
What am i missing here?个