从服务器获取自定义错误消息时遇到问题。
我使用axios打电话,Express作为服务器。
我得到了错误的状态,但没有成功只得到消息的状态。
Express Server响应
res.status(420).json({ message: "some problem" });
react axios调用
export function* deleteItem(action) {
try {
yield put(actions.deleteItemStart());
yield axios.delete("/items/item/" + action.itemId);
yield put(actions.deleteItemSuccess());
} catch (error) {
console.log(error);
yield put(actions.deleteItemFailed(error));
}
}
这是我在没有消息的情况下得到的错误
Error: Request failed with status code 420
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.handleLoad (xhr.js:61)
这是我的第一篇帖子,我希望一切都清楚。
提前感谢吉拉德:(
实际上,使用可以获得axios错误
catch(e){
console.log("error response:", e.response);
}
e.response包含服务器响应(如果有(。