Skip to content

Add typed error classes for database failures#1

Merged
deepa0128 merged 1 commit into
mainfrom
feat/typed-errors
Apr 23, 2026
Merged

Add typed error classes for database failures#1
deepa0128 merged 1 commit into
mainfrom
feat/typed-errors

Conversation

@deepa0128

Copy link
Copy Markdown
Owner

What

Introduces a typed exception hierarchy so callers can handle database errors by class rather than by parsing raw driver error objects.

DbError (base)
├── ConnectionError     — network / auth failures
├── ConstraintError     — unique, FK, not-null violations (carries .constraint name)
└── QueryTimeoutError   — statement killed after timeout

Each driver catches its native errors (pg SQLSTATE codes, mysql2 error codes) and maps them before they leave the driver boundary. All four error classes are exported from the package root.

Also included

  • Postgres: adds pool.on('error') handler so idle-client failures don't crash the process
  • MySQL: fixes SSL config ({}{ rejectUnauthorized: true }) to match Postgres behaviour
  • Both drivers: refactors transaction handling with a makeTxDriver helper to reduce duplication

@deepa0128
deepa0128 merged commit 8c2bd02 into main Apr 23, 2026
@deepa0128
deepa0128 deleted the feat/typed-errors branch April 23, 2026 09:37
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.

1 participant