RxJS 中的 catch 和 catchError 有什么区别。以及如何处理 API 调用返回的网络错误?

What is the difference between catch and catchError in RxJS. And How to handle the network error returned by API call?

mergeMap( (action)=>{

        const data = action.data;
        console.log(state$.value,'\n',action.data);

在此处调用 API。如何处理本次调用返回的网络错误?

from(axios.post('http://localhost:3000/addContactIntoDirectory', 
    {directoryId: state$.value.reducer1.SelectedDirectory, contact: data.contact})
))

基本上,在 RXJS 中 catchcatchError 是相同的。您可以参考文档 RxJs catch/catchError 了解更多信息。文档还指出我们必须从 catchError return observable。 查看与您的图书馆相关的给定示例 axios 上下文,

axios.post('/formulas/create', { name: "Atul", parts: "Mishra" }) 
.then(response => { 
    console.log(response) 
}).catch(error => { 
    console.log(error.response) 
});