@nxtedition/nxt-undici 6.2.19 → 6.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/request.js CHANGED
@@ -163,7 +163,14 @@ export function request(dispatch, url, opts) {
163
163
  let origin = url.origin
164
164
  if (!origin) {
165
165
  const protocol = url.protocol ?? 'http:'
166
- const host = url.host ?? `${url.hostname}:${url.port ?? (protocol === 'https:' ? 443 : 80)}`
166
+ const host =
167
+ url.host ??
168
+ (url.hostname ? `${url.hostname}:${url.port ?? (protocol === 'https:' ? 443 : 80)}` : null)
169
+
170
+ if (!host || !protocol) {
171
+ throw new InvalidArgumentError('invalid url')
172
+ }
173
+
167
174
  origin = `${protocol}//${host}`
168
175
  }
169
176
 
@@ -407,22 +407,30 @@ function makeResult(value) {
407
407
  }
408
408
  }
409
409
 
410
+ function printType(val) {
411
+ return val == null ? 'null' : typeof val === 'object' ? val.constructor.name : typeof val
412
+ }
413
+
410
414
  /**
411
415
  * @param {any} key
412
416
  */
413
417
  function assertCacheKey(key) {
414
- if (typeof key !== 'object') {
415
- throw new TypeError(`expected key to be object, got ${typeof key}`)
418
+ if (typeof key !== 'object' || key == null) {
419
+ throw new TypeError(`expected key to be object, got ${typeof printType(key)} [${key}]`)
416
420
  }
417
421
 
418
422
  for (const property of ['origin', 'method', 'path']) {
419
423
  if (typeof key[property] !== 'string') {
420
- throw new TypeError(`expected key.${property} to be string, got ${typeof key[property]}`)
424
+ throw new TypeError(
425
+ `expected key.${property} to be string, got ${printType(key[property])} [${key[property]}]`,
426
+ )
421
427
  }
422
428
  }
423
429
 
424
430
  if (key.headers !== undefined && typeof key.headers !== 'object') {
425
- throw new TypeError(`expected headers to be object, got ${typeof key}`)
431
+ throw new TypeError(
432
+ `expected headers to be object, got ${typeof printType(key)} [${key.headers}]`,
433
+ )
426
434
  }
427
435
  }
428
436
 
@@ -430,31 +438,39 @@ function assertCacheKey(key) {
430
438
  * @param {any} value
431
439
  */
432
440
  function assertCacheValue(value) {
433
- if (typeof value !== 'object') {
434
- throw new TypeError(`expected value to be object, got ${typeof value}`)
441
+ if (typeof value !== 'object' || value == null) {
442
+ throw new TypeError(`expected value to be object, got ${typeof printType(value)}`)
435
443
  }
436
444
 
437
445
  for (const property of ['statusCode', 'cachedAt', 'staleAt', 'deleteAt']) {
438
446
  if (typeof value[property] !== 'number') {
439
- throw new TypeError(`expected value.${property} to be number, got ${typeof value[property]}`)
447
+ throw new TypeError(
448
+ `expected value.${property} to be number, got ${printType(value[property])} [${value[property]}]`,
449
+ )
440
450
  }
441
451
  }
442
452
 
443
453
  if (typeof value.statusMessage !== 'string') {
444
454
  throw new TypeError(
445
- `expected value.statusMessage to be string, got ${typeof value.statusMessage}`,
455
+ `expected value.statusMessage to be string, got ${printType(value.statusMessage)} [${value.statusMessage}]`,
446
456
  )
447
457
  }
448
458
 
449
459
  if (value.headers != null && typeof value.headers !== 'object') {
450
- throw new TypeError(`expected value.rawHeaders to be object, got ${typeof value.headers}`)
460
+ throw new TypeError(
461
+ `expected value.rawHeaders to be object, got ${printType(value.headers)} [${value.headers}]`,
462
+ )
451
463
  }
452
464
 
453
465
  if (value.vary !== undefined && typeof value.vary !== 'object') {
454
- throw new TypeError(`expected value.vary to be object, got ${typeof value.vary}`)
466
+ throw new TypeError(
467
+ `expected value.vary to be object, got ${printType(value.vary)} [${value.vary}]`,
468
+ )
455
469
  }
456
470
 
457
471
  if (value.etag !== undefined && typeof value.etag !== 'string') {
458
- throw new TypeError(`expected value.etag to be string, got ${typeof value.etag}`)
472
+ throw new TypeError(
473
+ `expected value.etag to be string, got ${printType(value.etag)} [${value.etag}]`,
474
+ )
459
475
  }
460
476
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "6.2.19",
3
+ "version": "6.2.20",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",