Skip to content

Commit

Permalink
Update lib/errors.js
Browse files Browse the repository at this point in the history
Co-authored-by: Gar <gar+gh@danger.computer>
  • Loading branch information
lukekarrys and wraithgar committed May 1, 2024
1 parent 814cb93 commit aec3fa4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { URL } = require('url')
const { URL } = require('node:url')

function packageName (href) {
try {
Expand All @@ -24,7 +24,8 @@ class HttpErrorBase extends Error {
constructor (method, res, body, spec) {
super()
this.name = this.constructor.name
this.headers = typeof res.headers.raw === 'function' ? res.headers.raw() : res.headers
console.log(res.headers)
this.headers = typeof res.headers?.raw === 'function' ? res.headers.raw() : res.headers
this.statusCode = res.status
this.code = `E${res.status}`
this.method = method
Expand Down
4 changes: 2 additions & 2 deletions test/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ t.test('Unexpected www-authenticate error', t => {
})

t.test('error can take headers object', (t) => {
const e = new errors.HttpErrorBase('GET', { headers: { a: 1 } })
t.strictSame(e.headers, { a: 1 })
t.strictSame(new errors.HttpErrorBase('GET', { headers: { a: 1 } }).headers, { a: 1 })
t.strictSame(new errors.HttpErrorBase('GET', { }).headers, undefined)
t.end()
})

0 comments on commit aec3fa4

Please sign in to comment.