javascript - How to chain error.response.json() in a promise without nesting it in the catch? -
i'm trying figure out best way handle server error response promise
error.response.json(); without nesting in catch(). there way can done outside of catch , still called when there 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, }); }) );
is there way can done outside of catch , still called when there error?
no.
i'm trying figure out best way handle server error response
it works quite bit different, suspect wanted write is
return doget(`/rest/hello-world`) .then(json => ({ type: load_success, data: json.listresponse.data, }), error => error.response.json().then(result => ({ type: load_fail, error: result.error.message, })) ) .then(dispatch); you might want consider case error.response.json() rejects on malformed responses.
Comments
Post a Comment