How To Exit A Server Action in the Middle

Hi.
In some conditions, instead of using multiple nested if-else steps, we use RESPONSE step to stop the execution of a SA.
But this does not work well in case of schedulers, since response step is not supported and it generates “this.res.status is not a function” exception.

Is there any way other to stop the execution of a server action? Like a BREAK statement works in for loop.
Or if there is something that can be configured using custom module, that would do too. The requirement is that it should work in schedulers.

Hi buddy,

Below are all the links relevant to your question, you can pick the most appropriate one :wink: (it’s probably the 2nd link)





Honestly, it sounds like something Patrick could fix by creating a mock response object

1 Like

Unfortunately, none of these are quite relevant.
To put my issue in another terms: I need a way to cleanly exit a server action, so that it does not generate any exception.
Its not relevant to a loop, but more in terms of exiting a scheduler.

1 Like

Bump.
Any help here @patrick?

Made a better mock for the response object that should work in the scheduler. The mock object catches the send/json methods and set the headersSent property on the object which is used to to skip action steps after the response has been sent.

Here the update, unzip to lib/setup:
cron.zip (754 Bytes)

1 Like

Thanks will test asap and get back to you.

@patrick Was on a break, and have resumed work today.
We tested this an it works as expected - which solves the primary issue.

But for the sake of better UX, a separate step or renaming of “Response” to “Response and Exit” could be useful. Or maybe another way to inform the user on how the response step works.