Skip to content

Instantly share code, notes, and snippets.

@stewartpark
Created May 23, 2018 20:52
Show Gist options
  • Save stewartpark/fddf78b3d60263c38acb417ebec05f70 to your computer and use it in GitHub Desktop.
Save stewartpark/fddf78b3d60263c38acb417ebec05f70 to your computer and use it in GitHub Desktop.
A patch to `node-fetch` to cause random errors
--- node_modules/node-fetch/lib/index.js 2018-03-25 13:54:59.000000000 -0700
+++ node_modules/node-fetch/lib/index.patched.js 2018-05-23 13:51:07.000000000 -0700
@@ -249,6 +249,9 @@
return consumeBody.call(this).then(function (buffer) {
try {
+ if(Math.random() < 0.1) {
+ return Body.Promise.reject(new FetchError('random error raised as a test'));
+ }
return JSON.parse(buffer.toString());
} catch (err) {
return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
@@ -1361,6 +1364,10 @@
throw new Error('native promise missing, set fetch.Promise to your favorite alternative');
}
+ if(Math.random() < 0.1) {
+ throw new Error('random error raised as a test');
+ }
+
Body.Promise = fetch.Promise;
// wrap http.request into fetch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment