-
-
Save jakearchibald/8a9c47094b6e31de5cb2 to your computer and use it in GitHub Desktop.
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
var url = '/scripts/main.min.c18e3e78.js'; | |
var opaqueResponsePromise = function(response) { | |
console.log('opaque repsonse', response); | |
// Cache opaque response | |
}; | |
var basicResponsePromise = function(response) { | |
console.log('basic repsonse'); | |
// Parse the response | |
if(response.status !== 200) { | |
throw new Error('Bad status code'); | |
} | |
return response.text() | |
.then(function(text) { | |
console.log('Response.text is complete'); | |
}) | |
.catch(function(err) { | |
console.log('Oops = ', err); | |
}); | |
}; | |
fetch(url, {'mode': 'cors'}) | |
.then(function(response) { | |
if (response.type === 'opaque') { | |
console.log('The Response is opaque so we can\'t examine it'); | |
// Do something with the response (i.e. cache it for offline support) | |
return opaqueResponsePromise(response); | |
} | |
return basicResponsePromise(response); | |
}) | |
.catch(function(err) { | |
console.error('Fetch Error :-S', err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment