Reactjs Axios捕获承诺错误
我有以下axios呼叫:Reactjs Axios捕获承诺错误,reactjs,axios,Reactjs,Axios,我有以下axios呼叫: axios.put({API_IMAGE_URL}}`, imageData, { withCredentials: true, headers: { 'Content-Type': 'multipart/form-data' } }) .then(response => { axios.get(`${API_URL}/images/${response.data.id}`, { withCr
axios.put({API_IMAGE_URL}}`, imageData, { withCredentials: true, headers: { 'Content-Type': 'multipart/form-data' } })
.then(response => {
axios.get(`${API_URL}/images/${response.data.id}`, { withCredentials: true, headers: { 'Content-Type': 'multipart/form-data' } })
.then(response => {
var newFormat = response.data;
dispatch(updateFormat(newFormat))
});
}).catch((e) => {
console.log("Can't update image ", e);
本质上,我有一个图像对象,它被传递到一个url。从那里,我需要检索具有新ID的新图像对象,以便用于其他事情
如果我的图像太大,我会发现以下错误:
413 (Request Entity Too Large)
Uncaught (in promise) Error: Network Error
我的问题就在这里。它给了我这些错误,并且没有转到catch子句。有没有办法抓住这些承诺错误 像这样回报第二个axios承诺
axios.put({API_IMAGE_URL}}`, imageData, { withCredentials: true, headers: { 'Content-Type': 'multipart/form-data' } }).then(response => {
// Return the promise from here like this
return axios.get(`${API_URL}/images/${response.data.id}`, { withCredentials: true, headers: { 'Content-Type': 'multipart/form-data' } }).then(response => {
var newFormat = response.data;
dispatch(updateFormat(newFormat))
});
}).catch((e) => {
console.log("Can't update image ", e);
谢谢刚刚尝试了这个,我仍然得到网络错误,而不是抓住他们哦nvm只是在看错误的功能,它的工作!