feat: classify driver errors into client/transient/server for accurate HTTP status codes#170
feat: classify driver errors into client/transient/server for accurate HTTP status codes#170eugene-mobile wants to merge 1 commit into
Conversation
…e HTTP status codes
Introduces DriverError with errorClass ('client' | 'transient' | 'server')
so the query route can return 400, 503, or 500 rather than always 400.
- interface.ts: add DriverErrorClass type and DriverError class
- postgres.ts: wrap query/queryAll errors using pg error codes
(08xxx/53xxx/57xxx → transient, 42xxx/28xxx → client, rest → server)
- mongodb.ts: convert explicit throws in parseRequest/operations to
DriverError('client'), wrap operation errors via MongoNetworkError/
MongoServerSelectionError/MongoParseError type checks
- query.ts: map errorClass to HTTP status (client→400, transient→503,
server→500); unclassified errors default to 500
- Tests updated and extended for all three error classes
Closes #122
Co-authored-by: Eugene <eugene-mobile@users.noreply.github.com>
|
@claude review this PR |
|
Claude finished @eugene-mobile's task in 1m 59s —— View job PR Review: feat: classify driver errors into client/transient/server for accurate HTTP status codes
Overall this is a clean, well-structured implementation that meaningfully improves error signal fidelity. The architecture is correct, the guard against double-wrapping is well-placed, and the test coverage is thorough. A few findings below — one substantive gap worth fixing, one debatable classification, and some minor observations.
|
| Severity | Finding |
|---|---|
| Notable | 23xxx Postgres constraint violations classified as server (500) instead of client (400) |
| Minor | 40xxx transaction conflicts classified as server rather than transient |
| Minor | No Retry-After header on 503 responses |
| Info | MongoWriteConcernError falls through to server classification |
| Info | ping() / getSchemas() / etc. are not wrapped — acceptable if those routes have their own error handling |
The 23xxx gap is the most concrete correctness issue: a user sending a row that violates a unique constraint gets a 500 today (which signals a bug on our end) instead of a 400 (which correctly signals bad input). Everything else is either a minor improvement opportunity or informational.
Implements #122: introduces DriverError with errorClass so the query route returns 400/503/500 instead of always 400.
Changes:
Closes #122
Generated with Claude Code