| name | express-error-handler |
| description | Diagnose and fix Express.js error handling issues across all apps (FlowInCash, Crispi, MicroApps) |
| version | 1.0.0 |
| tags | ["express","error-handling","node","typescript"] |
Express Error Handler
Use this skill when an Express app returns 500 errors, crashes on unhandled rejections,
or logs error stack traces.
Applies To
- FlowInCash (
/media/bob/I/AI_Projects/FlowInCash)
- Crispi-app (
/media/bob/I/AI_Projects/Crispi-app)
- FliC-MicroApps (
/media/bob/I/AI_Projects/FliC-MicroApps)
- Crispi-MicroApps (
/media/bob/I/AI_Projects/Crispi-MicroApps)
Diagnosis Steps
- Read the error log — extract the stack trace and HTTP status code
- Classify the error:
TypeError / ReferenceError → code bug, likely missing null check
ECONNREFUSED / ETIMEDOUT → downstream service (DB, Plaid, AWS) is down
ValidationError / ZodError → bad input from client
ENOMEM / EMFILE → resource exhaustion
- Locate the handler — search
src/routes/ for the failing endpoint
- Check the middleware chain — errors may be swallowed before reaching the error handler
Fix Patterns
Missing async error propagation
router.get('/accounts', async (req, res) => {
const data = await fetchAccounts();
res.json(data);
});
router.get('/accounts', async (req, res, next) => {
try {
const data = await fetchAccounts();
res.json(data);
} catch (err) {
next(err);
}
});
Error handler not last in middleware chain
app.use('/api', routes);
app.use(errorHandler);
Leaking internal errors to clients
res.status(500).json({ error: err.message, stack: err.stack });
res.status(500).json({ error: 'Internal server error', requestId: req.id });
logger.error({ err, requestId: req.id, path: req.path });
Validation
- Run
npm test in the affected project
- Trigger the failing request to confirm the fix
- Check that error logs show structured output, no raw stack traces to client