Created
May 10, 2016 18:53
-
-
Save qrohlf/478310964d4280c0cfb9c4e1ac06a74f to your computer and use it in GitHub Desktop.
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
// Make fetch evil - useful for testing retry logic | |
// MAKE FETCH EVIL - THIS SHOULD NOT BE IN THE FINAL COMMIT | |
const _fetch = window.fetch | |
const evilFetch = function () { | |
const r = Math.random() | |
if (r < 0.5) { | |
return _fetch.apply(null, arguments) | |
} else if (r < 0.75) { | |
console.warn('mocking fetch with TypeError') | |
return Promise.reject(new TypeError('blarg')) | |
} else { | |
console.warn('mocking fetch with 404') | |
return _fetch('/this/will/404') | |
} | |
} | |
window.fetch = evilFetch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment