Replies: 1 comment
-
Can you share some code on what you are doing now? It's hard to improve when I don't know what to improve, and your description isn't very clear to me. I don't really like the proposed solution, it feels pretty weird that you as a user would be able to define error messages this way, it feels out of scope for an ORM. Keep in mind it's not the ORM that throws this, it's the database itself, based on the schema, so this will be always about matching the error message if you really want to know what caused what. It feels like the only way is what you are already doing, and you'd like to hide this in the ORM codebase? I am also not sure what boilerplate are you talking about, your proposal means adding new option to the unique decorator, which you dont really need to be able to detect the constraint name out of the error message. You will always need the catch clause and instanceof check, the only addition to that is something like |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem? Please describe.
It would be nice to have a less boilerplatey way of handling index errors. Currently, using postgres as a db, I have to do a check on the error type first, then do a switch for the
constraint
(which btw, having generics for the errors would be amazing as well), which I then have to do string matching, and based on the index name, I can then associate with a field in my model and show the appropriate error in my API.Describe the solution you'd like
I think it would be nice that mikro could associate the constraint field to the property on the model. Even better if there was a way to add the constraint validation error directly on the model itself
@Unique(name: "unique_username", violationError: "Not Unique")
so you'd simply have to return the message if the error is of typeUniqueConstraintViolationException
:Describe alternatives you've considered
Only one is to have boilerplate code each time I have to deal with constraints. To make it a bit better, I can create utility functions to handle some of the duplication of code, but it's not great...
Beta Was this translation helpful? Give feedback.
All reactions