How to send an exception or other "error" response from an Activity to its Workflow #164
Replies: 2 comments 3 replies
-
For anyone else with a similar question: I haven't been able to find a way to allow an exception to be thrown from an Activity and caught in a Workflow. I now return an object from the Activity, and the object has a property called |
Beta Was this translation helpful? Give feedback.
-
@travisaustin Have you taken a look at https://laravel-workflow.com/docs/failures-and-recovery#handling-exceptions the only way to get an exception to throw from an activity is for it to run out of tries. This isn't currently supported for child workflows, only activities. I'll do some research into adding that. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
For sake of example, let's say we have a Workflow
UserRegistration
. That workflow triggers a child workflowGetOrCreateRemoteUser
, and that child workflow has a few activities to interact with a remote API.In the event that the remote API returns an error, I want to pass that error back to the
UserRegistration
workflow to be handled.What's the best way for the Activity, started from a ChildWorkflow inside a Workflow, can send an exception or other "error" response back to the Workflow?
I tried throwing an Exception in the Activity. By default, an exception causes the Activity to retry forever (with backoff). If I set
$tries
or$maxExceptions
to 1 on the Activity class, throwing an exception causes the Activity to fail, but I can't seem to configure anything in the workflow to intercept the exception.I have considered using a special return variable in the activity, but it's starting to get convoluted (lots of checks for success after each step in the Workflow).
What's the best way to throw an Exception (or similar) in an Activity and have it bubble all the way back to the parent Workflow?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions