From d44f590e96493add56959cdac5e3254a678f92a4 Mon Sep 17 00:00:00 2001 From: Marc Bernard <59966492+mbtools@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:13:03 -0500 Subject: [PATCH 1/2] Improve warning for non-error status codes --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index c425f1e..cbc47bf 100644 --- a/index.js +++ b/index.js @@ -70,7 +70,7 @@ function createError () { } if (typeof status === 'number' && (status < 400 || status >= 600)) { - deprecate('non-error status code; use only 4xx or 5xx status codes') + deprecate('non-error status code ' + status + '; use only 4xx or 5xx status codes') } if (typeof status !== 'number' || From ac15e62cadcf3e06cb8f354cd969f649dfda09f9 Mon Sep 17 00:00:00 2001 From: Marc Bernard <59966492+mbtools@users.noreply.github.com> Date: Fri, 15 Dec 2023 16:27:29 -0500 Subject: [PATCH 2/2] Add unit test --- test/test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/test.js b/test/test.js index 0059d01..ff35f89 100644 --- a/test/test.js +++ b/test/test.js @@ -407,3 +407,17 @@ describe('HTTP Errors', function () { /* eslint-enable node/no-deprecated-api */ }) }) + +describe('Deprecation notice', function () { + it('createError() deprecated', function (done) { + process.on('deprecation', (warning) => { + assert.strictEqual(warning.name, 'DeprecationError') + assert.strictEqual(warning.message, 'non-error status code 999; use only 4xx or 5xx status codes') + done() + }) + + createError(999, { + id: 1 + }) + }) +})