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.

There's an End step no available in Wappler 6.7.3

What is the difference between end and response step?
Because in context of schedulers, Patrick had already solved the issue with an update.

Looks like you forgot to integrate code for "End" into production (windows)

{
status: "500",
message: "Action end doesn't exist in core",
stack: "Error: Action end doesn't exist in core
    at App._exec (E:\webs\extensions\lib\core\app.js:698:17)
    at App._exec (E:\webs\extensions\lib\core\app.js:675:20)
    at App.exec (E:\webs\extensions\lib\core\app.js:644:16)
    at App.define (E:\webs\extensions\lib\core\app.js:626:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
}

Have checked core.js and the end: function looks to be missing

1 Like

Indeed there was a small last-minute packaging issue. This is now fixed in an inline update.

The end step is almost the same as the response step, with response you can output your own custom status code and data while with end it will just output the current data from the executed steps.

1 Like

Thats what i was looking for when poking around in core.js.

So basically it just hard codes a response of 200 i assume.

It does simply output the data from before the end step and stops the execution of the flow, so no steps after the end step is executed.

This topic was automatically closed after 36 hours. New replies are no longer allowed.