Skip to content

Commit aec28f9

Browse files
committed
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
1 parent f6bec9f commit aec28f9

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,10 @@ exports = module.exports = function errorHandler (options) {
8484
}
8585

8686
return function errorHandler (err, req, res, next) {
87-
// respect err.statusCode
88-
if (err.statusCode) {
89-
res.statusCode = err.statusCode
90-
}
91-
92-
// respect err.status
9387
if (err.status) {
9488
res.statusCode = err.status
89+
} else if (err.statusCode) {
90+
res.statusCode = err.statusCode
9591
}
9692

9793
// default status code to 500

0 commit comments

Comments
 (0)