Replies: 2 comments 4 replies
-
Hey @mohs8421, thanks for the suggestions! Actually, this has been asked by a few members in the community. I think we can include the error code in the following three variants.
However, I believe the error code is db dependent so user have to match the error code itself based on the db backend. |
Beta Was this translation helpful? Give feedback.
3 replies
-
For this to be useful we could really do with some improvements upstream though: There is a PR currently open: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
Queries can fail for various reasons, I would like to get better details from sea-orm directly instead of having to parse the error code and message from the database.
Motivation
When an ActiveModel is saved, it can happen, that the query fails because some constraints defined in the database are not fullfilled.
For example I get something like this from a mariadb database:
Now I would have to parse the error code coming from the database and look up what it means in order to have my code react more specific to the error which occurred, like trying again, if the query was a deadlock-victim, or just returning the info that this already exists to the user.
The current implementation does not give me that info.
A simple implementation could be to just add an attribute to the errors which then contains the error code, so users could directly access that.
A more sophisticated variant could provide a unified interpretation of error codes of different database codes, I'm fine with any improvement, and might even think about providing my solution to the issue to the project, once I am happy with that myself.
Additional Information
Note, that sqlx already provides the error code separated, but it is only passed as string by sea-orm
Beta Was this translation helpful? Give feedback.
All reactions