Last active
July 26, 2019 23:00
-
-
Save kjin/61230fb50dcb6b6474ba83ad1df6a09d 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
// Plugin for superagent@5 | |
module.exports = [ | |
{ | |
file: '', | |
patch: (superagent, tracer) => { | |
const UnpatchedRequest = superagent.Request; | |
superagent.Request = Object.assign(function Request(...args) { | |
const result = UnpatchedRequest.apply(this, args); | |
// Request#end sends the actual request. | |
// It's called within a custom thenable's `then` implementation which, | |
// when `await`'d, loses context. | |
// This is a Node bug and is tracked here: | |
// https://github.com/nodejs/node/issues/22360 | |
this.end = tracer.wrap(this.end); | |
return result; | |
}, UnpatchedRequest); | |
superagent.Request.prototype = UnpatchedRequest.prototype; | |
} | |
} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment