Conversation
aaqilniz
force-pushed
the
feat/handle-database-errors
branch
2 times, most recently
from
July 5, 2026 05:37
5240504 to
0a2b09c
Compare
aaqilniz
marked this pull request as ready for review
July 5, 2026 11:56
aaqilniz
marked this pull request as draft
July 5, 2026 12:46
aaqilniz
force-pushed
the
feat/handle-database-errors
branch
2 times, most recently
from
July 5, 2026 16:06
dc6c5f5 to
b873faf
Compare
aaqilniz
marked this pull request as ready for review
July 5, 2026 17:04
aaqilniz
force-pushed
the
feat/handle-database-errors
branch
from
July 12, 2026 18:29
b873faf to
cf69ebd
Compare
achrinza
requested changes
Aug 13, 2026
achrinza
left a comment
Member
There was a problem hiding this comment.
I agree it's a good feature to have.
Though I'd push back on two points:
- Database-specific code should be in each database's NPM package.
@loopback/restcan 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)
- 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/restwhich users can customise?
aaqilniz
marked this pull request as draft
September 23, 2026 13:06
5 tasks done
aaqilniz
force-pushed
the
feat/handle-database-errors
branch
4 times, most recently
from
September 25, 2026 11:42
2c13ca2 to
0c265e3
Compare
aaqilniz
marked this pull request as ready for review
September 25, 2026 11:53
aaqilniz
force-pushed
the
feat/handle-database-errors
branch
from
September 27, 2026 04:41
febca87 to
5051210
Compare
Contributor
Author
|
Hi, @achrinza. Thanks for the feedback. I have just made the changes based on your feedback. The database-specific codes are mapped in the respective connector (Here is the PR in loopback-connector-mysql). Ultimately, the error is mapped at the REST level. |
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
aaqilniz
force-pushed
the
feat/handle-database-errors
branch
from
September 27, 2026 05:27
65bb81f to
ea38fd1
Compare
This branch has not been deployed
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
Standardizes database error handling across
@loopback/repositoryand@loopback/restby translating connector-level driver errors into domain-specific, protocol-neutral errors, which are then mapped to REST HTTP statuses.Key Changes
@loopback/repository:DatabaseErrorand domain-specific sub-classes (UniqueConstraintError,ForeignKeyConstraintError,NotNullConstraintError,LockConflictError,DatabaseConnectionError, etc.).handleRepositoryError()utility to intercept low-level driver error codes and normalize them into protocol-neutralDatabaseErrorinstances while retaining context/details.@loopback/rest:mapDatabaseErrorToHttpError()to map protocol-neutralDatabaseErrorcodes to appropriate HTTP status codes (400, 409, 422, 503, 504).RejectProviderto run the mapping automatically before serializing the error response.Architectural Notes
Connector-specific error translation is supposed to be handled at the connector level. Here are the changes to mysql-connector.
@loopback/repositorypurely consumes standardized code strings, maintaining complete separation between storage layer implementations and transport protocols.Dependent on PR@loopback-connector-mysql
Checklist
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated👉 Check out how to submit a PR 👈