diff --git a/lib/intercept.js b/lib/intercept.js index 2f5263894..82ff8ed4d 100644 --- a/lib/intercept.js +++ b/lib/intercept.js @@ -256,6 +256,16 @@ function overrideClientRequest() { // Define the overriding client request that nock uses internally. function OverriddenClientRequest(options, cb) { + if (!options) { + // In principle, there is no reason we couldn't support this. However it + // doesn't work, and fixing it seems low priority. Giving an explicit + // error seems nicer than crashing with a weird stack trace. + // https://github.com/nock/nock/pull/1386 + throw Error( + 'Creating a client request with empty `options` is not supported in Nock' + ) + } + // TODO-coverage: Remove this conditional, as it is always true in Node 8+. if (http.OutgoingMessage) http.OutgoingMessage.call(this) diff --git a/lib/request_overrider.js b/lib/request_overrider.js index 4fb4d48fe..b0d55c7f9 100644 --- a/lib/request_overrider.js +++ b/lib/request_overrider.js @@ -86,7 +86,7 @@ function RequestOverrider(req, options, interceptors, remove, cb) { // We may be changing the options object and we don't want those // changes affecting the user so we use a clone of the object. - options = _.clone(options) || {} + options = _.clone(options) response.req = req