Filament exception handling
What is the best practice for exception handling?
Example:
I have "Detach" action and somewhere in model observer I am checking that the action is not allowed for this particular record and want to throw an exception.
I understand that can disable the action button for this record based on the same condition however I cannot relay only on frontend allowed actions but should ensure that the record is never detached.
How can I make it sent as Failure Notification? I used to work with Nova and it sends error notification for all exceptions thrown in models.
Do I miss something?
4 Replies
Not sure if this is exactly what you are looking for but here's a pattern I'm using extensively with custom Actions:
What about non-custom action? Currently, I am using Detach action on RelationManager. However, on model level I am restricting the ability to detach for some cases.
If I throw an exception from the model and it just displays the expection page. My expectation was that it would show the exception message as a failure notification but I cannot find how to configure it in the way.
Take a look at your Relation manager's base class and find out the method that handles saving the relationship. override this method in your sub class and handle the error there using Patrick's idea above. Let the documentation guide you.
Thank you, will try!