I'm trying to figure out the best way to handle the server error response promise
error.response.json();
without nesting it in the catch(). Is there a way this can be done outside of the catch and still only be called when there is an error?
return doGet(`/rest/hello-world`)
.then(json => json.ListResponse)
.then(result => {
return dispatch({
type: LOAD_SUCCESS,
data: result.data,
});
})
.catch(error =>
error.response.json().then(result => {
return dispatch({
type: LOAD_FAIL,
error: result.error.message,
});
})
);