我有以下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}`, { 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的图像对象。从那里,我需要检索新的Image对象及其用于其他事物的新ID。
如果我的图片太大,我会出现以下错误:
413 (Request Entity Too Large)
Uncaught (in promise) Error: Network Error
我的问题在于此。它给了我这些错误,并没有去catch条款。有没有办法捕捉这些承诺错误?
答案 0 :(得分:1)
只需返回第二个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);