refactor(error-handling): centralize duplicate try/catch into Express error middleware#192
Open
Satvik77777 wants to merge 1 commit into
Open
Conversation
- Created globalErrorHandler and asyncHandler middleware - Replaced duplicate try/catch blocks across agreements, crud, and mcp handlers - Stripped raw SQL and full request bodies from stdout - Ensured 500 JSON-RPC compatibility on /mcp initialization Signed-off-by: Satvik77777 <satvikaini02@gmail.com>
77f62d6 to
81a999c
Compare
Contributor
Author
|
Hi @niallroche @mttrbrts — this PR centralizes the |
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.
Summary
The same try/catch → console.log → res.status(500) pattern
was duplicated 20+ times across agreements.ts, crud.ts,
and mcp.ts. Several console.log statements also exposed
PII and internal details to stdout. This PR centralizes
error handling into a single Express error middleware.
What this PR does
New file — server/middleware/errorHandler.ts
location, replaces 20+ duplicate catch blocks
errors via next() without try/catch in every route
paths from leaking to API clients
Refactor — agreements.ts
Refactor — crud.ts
which leaked raw SQL query structure to stdout
Refactor — mcp.ts
non-sensitive context only
Why this matters
Security
Raw contract data, SQL queries, and stack traces were
being logged to stdout. In any hosted environment these
appear in server logs accessible to operators and
potentially leaked in log aggregation tools.
Maintainability
20+ identical catch blocks meant any change to error
handling required editing every handler file. Now
there is one place to update.
Reliability
asyncHandler ensures unhandled promise rejections in
route handlers are always caught and forwarded to
Express error handling — preventing silent process
crashes in Node.js.
References
Author Checklist