【发布时间】:2018-09-21 21:18:20
【问题描述】:
我正在使用 redux thunk 在操作中获取一些数据
function handleErrors(response) {
console.log(response)
if (!response.ok) {
throw Error(response.statusText);
}
return response;
}
export const something = (var) => dispatch => {
fetch(`${url}/something`, {credentials: 'include'})
.then(handleErrors)
.then(res => res.json())
.then(res =>
dispatch({
type: SOMETHING,
payload: res
})
)
.catch(error =>
dispatch({
type: ERROR,
payload: error
})
)
我的快递服务器出现错误时响应“一些错误”
return res.status(500).send({ message: 'some error' });
当它获取错误 (500) 时,它的消息是通用的“内部服务器错误”。
如何在 fetch 中获取“一些错误”?
【问题讨论】:
-
试试这个 github.com/github/fetch/issues/203#issuecomment-143347675
标签: javascript redux react-redux fetch-api redux-thunk