From 5ac4225555e30482fdbf519e42b2136d211e9091 Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 9 Nov 2018 20:48:15 -0800 Subject: [PATCH] feat: error.status (deprecate error.code) --- lib/http-error.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/http-error.js b/lib/http-error.js index 8eb9f2f6c..fe410e986 100644 --- a/lib/http-error.js +++ b/lib/http-error.js @@ -1,5 +1,5 @@ module.exports = class HttpError extends Error { - constructor (message, code, headers) { + constructor (message, statusCode, headers) { super(message) // Maintains proper stack trace (only available on V8) @@ -9,7 +9,13 @@ module.exports = class HttpError extends Error { } this.name = 'HttpError' - this.code = code + this.status = statusCode + Object.defineProperty(this, 'code', { + get () { + console.warn('`error.code` is deprecated, use `error.status`.') + return statusCode + } + }) this.headers = headers } }