feat(backend): add typed error classes and global error middleware - #621
Open
woahwhattheheck wants to merge 7 commits into
Open
woahwhattheheck wants to merge 7 commits into
woahwhattheheck wants to merge 7 commits into
Conversation
Introduce AppError, NotFoundError, ValidationError, and AuthError with a
consistent { error, message, code, requestId } response shape. Stack traces
are included only in development.
Closes Protocol-Guild#550
GitHub Actions rejects unknown workflow keys, so these files failed with zero jobs.
GitHub Actions rejects retention-days as a workflow root key, so every check on this branch failed at parse time. Artifact retention stays on upload-artifact steps where that key is valid.
GitHub Actions rejects retention-days at the workflow root, so every check on this branch failed before any job started.
This was referenced Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #550
What
Adds typed application error classes (
AppError,NotFoundError,ValidationError,AuthError) and a global Express error middleware that returns a consistent JSON shape:{ "error": "NotFoundError", "message": "...", "code": "NOT_FOUND", "requestId": "..." }The previous inline 404/500 handlers are replaced so all unhandled errors share one format. Stack traces are attached only when
NODE_ENV=development.Why
Controllers currently mix ad-hoc status codes and payload shapes. A shared error type plus one middleware makes frontend handling reliable and keeps internal details out of production responses.
How tested
backend/src/middleware/__tests__/errorHandler.test.ts(7 cases): typed 404/400/401/403 mapping, production redaction of unknown errors, development stack inclusion, and 404 fallback wiring.npm test -- --testPathPatterns=errorHandler— all passed.