I have a 400 returning a body with errors I need to get at. However, since fetch doesn't actually fail that status code, I handle it in the then and return a rejected Promise. But, because then generally returns a Promise, I can't issue a reject without awaiting the response from json().
dispatch({
type: 'LOGIN',
payload: fetch(`${host}/api/signin/`, {
method: 'POST',
body: data
}).then(async res => {
if (res.status >= 400) {
return Promise.reject(await res.json());
}
return await res.json();
})
});
Is there a better way to handle this? It's technically working, but I feel like I'm probably handling it wrong by making then synchronous.