Skip to content

feat: handle database errors - #11645

Open
aaqilniz wants to merge 1 commit into
loopbackio:masterfrom
aaqilniz:feat/handle-database-errors
Open

feat: handle database errors#11645
aaqilniz wants to merge 1 commit into
loopbackio:masterfrom
aaqilniz:feat/handle-database-errors

Conversation

@aaqilniz

@aaqilniz aaqilniz commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

The loopback app generally returns a 500 error code for most database-related errors. This PR adds a generic database error class and returns an appropriate error response by intercepting and modifying it at legacy-datasource-juggler.

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
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

@aaqilniz
aaqilniz force-pushed the feat/handle-database-errors branch 2 times, most recently from 5240504 to 0a2b09c Compare July 5, 2026 05:37
@aaqilniz
aaqilniz marked this pull request as ready for review July 5, 2026 11:56
@aaqilniz
aaqilniz marked this pull request as draft July 5, 2026 12:46
@aaqilniz
aaqilniz force-pushed the feat/handle-database-errors branch 2 times, most recently from dc6c5f5 to b873faf Compare July 5, 2026 16:06
@aaqilniz
aaqilniz marked this pull request as ready for review July 5, 2026 17:04
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
@aaqilniz
aaqilniz force-pushed the feat/handle-database-errors branch from b873faf to cf69ebd Compare July 12, 2026 18:29

@achrinza achrinza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's a good feature to have.

Though I'd push back on two points:

  1. Database-specific code should be in each database's NPM package. @loopback/rest can then parse the generalised Error object and map it
    • This would improve future extensibility and ensure that first-party and third-party LB4 connectors have the same features accessible.
    • This allows for non-REST applications to do their own mapping (i.e. don't add REST-specific code in @loopback/repository)
  2. Opt-out mechanism
    Arguably this is security through obscurity, but this feature does necessarily expose some of the inner-workings of the application. IIRC 5xx errors are sanitised, but 4xx are not. So perhaps we should build an extensible "mapping" mechanism in @loopback/rest which users can customise?

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.

2 participants