Performance: Centralized error handling
MEDIUM IMPACT
This affects server response time and resource usage by managing errors efficiently in one place.
app.use((err, req, res, next) => {
console.error(err);
res.status(500).send('Internal Server Error');
});app.get('/data', (req, res) => { try { // some code } catch (err) { res.status(500).send('Error occurred'); } }); app.post('/data', (req, res) => { try { // some code } catch (err) { res.status(500).send('Error occurred'); } });
| Pattern | CPU Usage | Memory Usage | Response Consistency | Verdict |
|---|---|---|---|---|
| Multiple try-catch in routes | High due to repeated error checks | Higher due to duplicated code | Inconsistent error messages | [X] Bad |
| Centralized error middleware | Lower by handling errors once | Lower due to less code duplication | Consistent error responses | [OK] Good |