【发布时间】:2017-01-03 00:32:30
【问题描述】:
我有以下代码进行 API 调用并基于 HTTP 响应,它在我的 redux reducer 中调度某些操作。
问题在于,如果 API 调用失败,它会在控制台中显示它,即使处理不成功调用的部分代码执行得很好。我怎样才能防止这种情况?我已经在处理不成功的 API 调用,因此控制台中不会显示任何内容。
export const someApiCall = () => {
return (dispatch) => fetch('/api/somefunction', fetchOptionsGet())
.then((response) => {
if(response.ok) {
// Success. Dispatch some actions
} else {
// Failed call. Dispatch some other actions
}
})
}
【问题讨论】:
标签: redux fetch react-redux