From aec28f994e393ddb4d629e941136095b9bf2e493 Mon Sep 17 00:00:00 2001 From: Ayoub-Mabrouk Date: Mon, 15 Dec 2025 22:54:47 +0100 Subject: [PATCH] refactor: consolidate status code assignment logic Replace two separate if statements with an else-if chain to: - Make err.status precedence over err.statusCode explicit - Avoid unnecessary assignment when both properties exist --- index.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 333a02e..04abb43 100644 --- a/index.js +++ b/index.js @@ -84,14 +84,10 @@ exports = module.exports = function errorHandler (options) { } return function errorHandler (err, req, res, next) { - // respect err.statusCode - if (err.statusCode) { - res.statusCode = err.statusCode - } - - // respect err.status if (err.status) { res.statusCode = err.status + } else if (err.statusCode) { + res.statusCode = err.statusCode } // default status code to 500