Skip to content

Instantly share code, notes, and snippets.

@jakearchibald
Forked from gauntface/gist:3415a0aeea34806a837a
Last active August 29, 2015 14:17
Show Gist options
  • Save jakearchibald/8a9c47094b6e31de5cb2 to your computer and use it in GitHub Desktop.
Save jakearchibald/8a9c47094b6e31de5cb2 to your computer and use it in GitHub Desktop.
function assertOkResponse(response) {
if (response.type === 'opaque' || response.status === 200) {
return response;
}
throw Error("Bad response: " + response.status);
}
fetch(url, {'mode': 'cors'}).then(assertOkResponse).then(function(response) {
// cache
}).catch(function(err) {
console.error('Fetch Error :-S', err);
throw err;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment