[QOTD-18] Implement global error-handling middleware #5
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ssmp/qotd-18-r6"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds a global Express error-handling middleware so unhandled errors return a safe, generic HTTP 500 response instead of leaking internals or stack traces to clients.
Changes Made
src/middleware/error.tswith a four-argument Express error handler that logs the error server-side viaconsole.errorand responds with HTTP 500 and{ error: 'Internal server error' }src/server.ts, a minimal Express app entry point that mountsexpress.json()and registers the error handler last (required sinceserver.tsdid not yet exist in this repo)Notes
server.tscurrently only wires up JSON body parsing and the error handler; routes, the quote store, and validation are tracked separately under QOTD-13/QOTD-7/QOTD-10 and will be merged into this entry point in follow-up work. Verified withtsc --noEmit(clean) andnpm test(1/1 passing).Task: QOTD-18
Commit: [QOTD-18] Implement global error-handling middleware
Add src/middleware/error.ts with a four-argument Express error handler that logs errors server-side via console.error and responds with HTTP 500 and a generic { error: 'Internal server error' } body, never leaking stack traces to the client. Register it last in a new src/server.ts entry point.✅ AI review (ai-reviewer) — no issues found. Reviewed against the project rules; nothing rule-citable to flag.
Checkout
From your project repository, check out a new branch and test the changes.