[FEATURE PROPOSAL] Fetch should throw an error if the response fails
EduardoAC opened this issue · 2 comments
EduardoAC commented
Currently the implementation of the adapter does not provide any information when fetch fail for an 404 being hard to track or redirect in the application.
My proposal is adjust the current https://github.com/lexich/redux-api/blob/master/src/adapters/fetch.js#L27 to follow the idea of this issue JakeChampion/fetch#155
Which means that our current implementation will look like
export default function (fetch) {
return (url, opts)=> fetch(url, opts).then(resp=>
toJSON(resp).then((data)=> {
if (resp.status >= 200 && resp.status < 300) {
return data;
} else if (resp.status >= 400) {
const error = new Error(response.statusText || response.status)
error.response = response
return Promise.reject(error)
} else {
return Promise.reject(data);
}
}));
}
lexich commented
Would you like to make PR?
EduardoAC commented
Sure, I wanted to discuss the implementation before I move forward.