我正在使用redux thunk在一个action中获取一些数据。
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
})
)
我的Express服务器在出现错误时会响应“some error”
return res.status(500).send({ message: 'some error' });
当它获取数据时,如果出现错误(500),其消息将是通用的“内部服务器错误”。
我如何在获取数据时获得“一些错误”?