Performance: Error-handling middleware signature
MEDIUM IMPACT
This affects server response time and error handling efficiency, impacting how quickly errors are caught and responses are sent.
app.use((err, req, res, next) => {
if (err) {
res.status(500).send('Error');
} else {
next();
}
});app.use((req, res, next) => {
// error handling logic but missing 'err' parameter
if (someError) {
res.status(500).send('Error');
} else {
next();
}
});| Pattern | Middleware Calls | Error Handling Efficiency | Response Delay | Verdict |
|---|---|---|---|---|
| Missing error param middleware | All requests pass through | Low - not triggered automatically | Increased delay due to extra calls | [X] Bad |
| Correct error-handling middleware | Only error requests pass | High - triggered only on errors | Minimal delay, faster error response | [OK] Good |