Skip to content

Commit 5ac4225

Browse files
committed
feat: error.status (deprecate error.code)
1 parent 549712a commit 5ac4225

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/http-error.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = class HttpError extends Error {
2-
constructor (message, code, headers) {
2+
constructor (message, statusCode, headers) {
33
super(message)
44

55
// Maintains proper stack trace (only available on V8)
@@ -9,7 +9,13 @@ module.exports = class HttpError extends Error {
99
}
1010

1111
this.name = 'HttpError'
12-
this.code = code
12+
this.status = statusCode
13+
Object.defineProperty(this, 'code', {
14+
get () {
15+
console.warn('`error.code` is deprecated, use `error.status`.')
16+
return statusCode
17+
}
18+
})
1319
this.headers = headers
1420
}
1521
}

0 commit comments

Comments
 (0)