Skip to content

feat: normalize mysql error codes to standard domain codes - #924

Open
aaqilniz wants to merge 1 commit into
loopbackio:masterfrom
aaqilniz:feat/db-error-handling
Open

aaqilniz wants to merge 1 commit into
loopbackio:masterfrom
aaqilniz:feat/db-error-handling

Conversation

@aaqilniz

@aaqilniz aaqilniz commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

LoopBack applications previously returned generic database-specific error responses or raw SQLSTATE codes for PostgreSQL failures. This PR introduces a PostgreSQL error normalization module (lib/normalize-error.js) that intercepts raw PostgreSQL driver errors and maps them to standard, protocol-neutral domain codes using 5-character SQLSTATE codes.

Error Code Mappings

PostgreSQL SQLSTATE Condition / Error Name Normalized Domain Code
23505 unique_violation UNIQUE_CONSTRAINT_VIOLATION
42P01 undefined_table TABLE_NOT_FOUND
42703 undefined_column COLUMN_NOT_FOUND
23503 foreign_key_violation FOREIGN_KEY_VIOLATION
23502 not_null_violation NOT_NULL_VIOLATION
23514 check_violation CHECK_CONSTRAINT_VIOLATED
22P02, 22001, 22003 Invalid text representation / Data exceptions DATA_TYPE_MISMATCH
40P01, 40001 Deadlock / Serialization failure LOCK_CONFLICT
08000, 08003, 08006 Connection exceptions CONNECTION_FAILURE
N/A (Lifecycle) Inactive or closed transaction usage TRANSACTION_NOT_ACTIVE

Depends on PR#11645

Checklist

  • DCO (Developer Certificate of Origin) signed in all commits
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • Commit messages are following our guidelines

Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
@aaqilniz
aaqilniz force-pushed the feat/db-error-handling branch from dc20805 to 4a092ae Compare November 9, 2026 16:19
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