Replies: 1 comment
-
I don't think hyper-specializing the exception at model level is useful, especially if the goal is to be able to end up with However, if you consider it's related to your proposal, I think it would be interesting to be able to recover the model who threw the exception like it's possible in Laravel. Something like: if (error.code === 'E_ROW_NOT_FOUND') {
console.log(error.model.name) // error.model is User model class
}
```
It was already very briefly discussed here : https://github.com/orgs/adonisjs/discussions/3946 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context
Currently, in AdonisJS, when using the
findOrFail
method on a Lucid model, if the record is not found, a lucidE_ROW_NOT_FOUND
error is thrown by default. While this exception provides useful information, it would be beneficial to allow developers to customize this default error at the model level.Proposal
I propose adding a feature that allows setting a default exception for record retrieval methods (like
findOrFail
) directly on the respective model. This configuration would enable specifying a custom exception for cases where the record is not found.Example
Here’s an example of what the implementation could look like:
Benefits
Conclusion
This feature would provide more flexibility and clarity in error handling within AdonisJS applications. I would be happy to collaborate on the implementation of this proposal or provide any other necessary contribution.
Beta Was this translation helpful? Give feedback.
All reactions