Summary
The API Gateway has no global Express error handler. Async middleware rejections become unhandled promise rejections, crashing the process in Node.js 20+.
Affected File
services/api-gateway-node/index.js
Root Cause
Express 5 requires a global error handler middleware to catch errors from async route handlers and middleware. Without it:
// Missing:
app.use((err, req, res, next) => {
console.error('Unhandled error:', err);
res.status(500).json({ error: 'Internal server error' });
});
Any synchronous throw or async rejection in route handlers or middleware will:
- Crash the process (Node.js 20+ terminates on unhandled rejections)
- Return a generic HTML error page instead of JSON
- Leak stack traces to the client
Additionally, there is no graceful shutdown:
// Missing:
process.on('SIGTERM', () => {
server.close(() => process.exit(0));
});
Impact
- Any unhandled error crashes the entire API Gateway
- All downstream services become unreachable
- Unhandled promise rejections terminate the Node.js process
- In production, this causes cascading failures across the entire platform
Fix Required
- Add a global Express error handler:
app.use((err, req, res, next) => {
logger.error('unhandled_error', { error: err.message, stack: err.stack });
res.status(err.status || 500).json({ error: 'Internal server error' });
});
- Add graceful shutdown handlers for SIGTERM/SIGINT
- Use
express-async-errors or ensure all async handlers catch errors
Summary
The API Gateway has no global Express error handler. Async middleware rejections become unhandled promise rejections, crashing the process in Node.js 20+.
Affected File
services/api-gateway-node/index.jsRoot Cause
Express 5 requires a global error handler middleware to catch errors from async route handlers and middleware. Without it:
Any synchronous throw or async rejection in route handlers or middleware will:
Additionally, there is no graceful shutdown:
Impact
Fix Required
express-async-errorsor ensure all async handlers catch errors