Why should I never return stack traces in a production 500 response?
Stack traces leak file paths, dependency versions, SQL queries, and internal secrets to attackers. Log them server-side and return only an opaque `request_id`.
HTTP 500 Internal Server Error is the catch-all server crash code. Fast triage means correlating the request ID with application stack traces, missing environment variables, database connection errors, or broken `.htaccess` syntax.
// Express.js global error middleware
app.use((err, req, res, next) => {
const requestId = req.headers['x-request-id'] || crypto.randomUUID();
console.error({ requestId, err });
res.status(500).json({
type: 'about:blank',
title: 'Internal Server Error',
status: 500,
request_id: requestId,
});
});
curl -i -sS -H 'X-Request-Id: debug-500-01' https://api.example.com/v1/checkout
Stack traces leak file paths, dependency versions, SQL queries, and internal secrets to attackers. Log them server-side and return only an opaque `request_id`.
Check `/var/log/nginx/error.log` first, then your upstream app journal (`journalctl -u app -n 100`) or container logs (`docker logs`).
Yes—validate all required environment variables at startup so deployments fail fast before receiving live traffic.