【发布时间】:2021-11-10 19:22:02
【问题描述】:
我正在使用带有 REACTjs 的 AXIOS
我想要一个功能,如果我的第一个 API(GET) 调用返回 Not Found
状态码然后我想有效地发送另一个呼叫。
虽然我通过.catch 方法以Promise<pending> 的形式获取了一些数据。请帮助!!!
【问题讨论】:
标签: reactjs api axios react-hooks
我正在使用带有 REACTjs 的 AXIOS
我想要一个功能,如果我的第一个 API(GET) 调用返回 Not Found
状态码然后我想有效地发送另一个呼叫。
虽然我通过.catch 方法以Promise<pending> 的形式获取了一些数据。请帮助!!!
【问题讨论】:
标签: reactjs api axios react-hooks
为什么不在 catch 块中添加条件来检查状态?
例如:
axios.get('/first-call')
.then(resp => {
//handle successful response
})
.catch(error => {
if (error.response && error.response.status === 404) {
// make second API call
}
});
【讨论】: