Last active
July 5, 2016 14:19
-
-
Save teameh/28ccb3f7b2c8deb69d5a958274529a63 to your computer and use it in GitHub Desktop.
Github Fetch error example
This file contains 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
// Changed after code review | |
// http://codereview.stackexchange.com/questions/133911 | |
function checkStatus(response) { | |
if (response.status >= 200 && response.status < 300) { | |
return Promise.resolve(response); | |
} | |
return response.json() | |
.catch(() => { | |
const error = new Error(response.statusText); | |
return Promise.reject(Object.assign(error, response)); | |
}) | |
.then((json) => { | |
const error = new Error(json.message || response.statusText); | |
return Promise.reject(Object.assign(error, response)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment