feat(backend): add typed error classes and global error middleware - #621
Open
woahwhattheheck wants to merge 18 commits into
Open
woahwhattheheck wants to merge 18 commits into
woahwhattheheck wants to merge 18 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
Normalize malformed and oversized request bodies without exposing parser input. Keep request IDs, typed application errors, and development-only stacks intact.
Keep unsupported charset/encoding responses at 415 and form parameter overflow at 413, with constant sanitized messages. Add five actual Express parser regressions to the existing error-handler suite.
Correct the README's universal two-field error claim. Document the typed handler envelope, recognized parser status/code mappings, request IDs, environment-dependent stacks and direct payroll response boundary. Only the Error Handling subsection changes. Current source and existing cases were read; no runtime, build or maintained checks were replayed.
Forward service failures from all twelve payroll handlers to the existing global error boundary. Use ValidationError for seven missing-query paths and NotFoundError for missing transactions. Keep route/authentication order, service arguments and successful response bodies unchanged. Focused source-level before/after check: 12 preserved successes/service calls, 12 forwarded service failures, 7 validation mappings, 1 not-found mapping and 2 preserved typed errors. Executed actual TypeScript handlers and AppError classes with Express registration, services, authentication and logger collaborators stubbed; not a full application, HTTP or database test.
Reuse the completed CI repair from 0418d00. Remove unsupported workflow-root retention settings, preserve Scaffold failure through tee with explicit Bash, restore the exact executable placeholder checker from 61311eb, and include checker/workflow edits in the existing secrets-check triggers. Recipient build 5202999, secrets workflow b8d3b7e, and placeholder manifest f4bdde8 match the previously executed repair inputs. Reuse that evidence; no application build, new suite, hosted execution, release or deployment is asserted. All application and documentation source is unchanged.
Keep the original error-response contract for non-Error thrown values whose string conversion fails. Add focused regression rows to the maintained middleware suite and record the direct-handler execution and its limits. Compose on the existing CI-repair successor without changing its workflows or executable checker.
Keep operational client messages and development diagnostics unchanged. Add focused cases for server and non-operational error response messages.
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.