You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The idea is to either make after_actions be also called when an action early exits via fail_and_return! or to have a special hook for that purpose.
A possible use-case (from a real project I work on) is to e.g. log failed action error messages along with some payload, but in a single place, regardless of whether it was fail or fail_and_return!.
The text was updated successfully, but these errors were encountered:
I've just looked up the documentation to remind me how this works.
The after_action hook was created for instrumentation purposes only. We "lifted" this idea from AOP.
You would have to catch the exception in your action, set that exception in the context, and use the after_action hook to "monitor" and "report" the error from the context. The nice thing about this is that you could make the exception handling short in your code, and you could put the logging into the after_action, decoupling how the "reporter" works apart from your business logic.
I see. But what if an action didn't fail because of an exception? What if an author has decided to fail early just because some business logic condition hasn't been fulfilled? Looks like I would have to just call next by myself, right?
Hello there!
The idea is to either make
after_actions
be also called when an action early exits viafail_and_return!
or to have a special hook for that purpose.A possible use-case (from a real project I work on) is to e.g. log failed action error messages along with some payload, but in a single place, regardless of whether it was
fail
orfail_and_return!
.The text was updated successfully, but these errors were encountered: