Skip to content

feat(backend): add typed error classes and global error middleware - #621

Open
woahwhattheheck wants to merge 7 commits into
Protocol-Guild:mainfrom
woahwhattheheck:wire/payd-550-error-middleware
Open

woahwhattheheck wants to merge 7 commits into
Protocol-Guild:mainfrom
woahwhattheheck:wire/payd-550-error-middleware

Conversation

@woahwhattheheck

Copy link
Copy Markdown

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

  • Unit tests in 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.

woahwhattheheck and others added 5 commits September 24, 2026 15:36
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add proper error handling middleware with typed error classes

1 participant