Skip to content

Commit 9fd0433

Browse files
authored
fix: don't throw on older versions of Node.js 6 (#711)
The `url.URL` object was added in Node.js v6.13.0. If you tried to perform a `foo instanceof url.URL` on earlier versions, the code would throw the following exception: TypeError: Expecting a function in instanceof check, but got undefined
1 parent fa24ae1 commit 9fd0433

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/instrumentation/http-shared.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ function isRequestBlacklisted (agent, req) {
8383
// NOTE: This will also stringify and parse URL instances
8484
// to a format which can be mixed into the options object.
8585
function ensureUrl (v) {
86-
if (typeof v === 'string' || v instanceof url.URL) {
87-
return url.parse(String(v))
86+
if (typeof v === 'string') {
87+
return url.parse(v)
88+
} else if (v instanceof url.Url) {
89+
return v
90+
} else if (url.URL && v instanceof url.URL) { // check for url.URL because it wasn't added until Node.js 6.13.0
91+
return url.parse(v.toString())
8892
} else {
8993
return v
9094
}

0 commit comments

Comments
 (0)