Created
January 10, 2018 21:31
-
-
Save davidicus/235c8fba63c2c3c8f987ab3dee7003dd to your computer and use it in GitHub Desktop.
Fetch api and make error fail loudly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch(path.join(__dirname, `/api/structures/overview`), { | |
method: `GET`, | |
credentials: 'include' | |
}) | |
.then(response => { | |
const json = response.json(); | |
if (response.status >= 200 && response.status < 300) { | |
return json; | |
} else { | |
return json.then(Promise.reject.bind(Promise)); | |
} | |
}) | |
.then(responseJson => { | |
dispatch(getStructuresSuccess(responseJson)); | |
return responseJson; | |
}) | |
.catch((error) => { | |
dispatch(getStructuresFailure(error)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment