Sign In Register

How can we help you today?

Start a new topic
Answered

How to stop/break Cloud Code execution?

Is there a way to stop/break Cloud Code execution and return script data?


if(something wrong){

  break and return some script data;

}

continue script


Best Answer

You can use Spark.exit(); to stop code execution.


If you have an error, you can set it as script data, then call Spark.exit();


i.e 


 

Spark.setScriptError("error", "This is my error that happened")
Spark.exit();

 


Hi Irakli,


Can you let us know what you are trying to achieve here ? The cloud code debugger should be quite helpful to you for this. With “Break On Error” enabled in the debugger should your script hit a breakpoint it will stop executing and return an error. Alternatively you could put your code into a function and surround it with a try/catch and return if a catch is called.


Thanks,

Liam

Hello Liam,


I want to add to Cloud Code beginning something like this:


if (userScore < 0){

  // I'm searching something to put here. I want to tell GS to don't execute code after this if statement and send response with script data. Usually "return" is used for this in scripting but it doesn't work here. 

}


// Some long code here, which shouldn't execute if userScore < 0


Of course I can place everything after if statement in "else" and It wouldn't run, but I frequently set filters using "return" and am interested to find this in GS too.


Thanks!

OK, I'll put it into "else". :)


Anyway, I'll be glad to hear if there's a "return" command.

You can put all of your code for that event in a function, and call that function. Then you can call return in the function as you want.

Answer

You can use Spark.exit(); to stop code execution.


If you have an error, you can set it as script data, then call Spark.exit();


i.e 


 

Spark.setScriptError("error", "This is my error that happened")
Spark.exit();

 

Hi Greg,


Spark.exit() was what I needed at that moment.


Thanks!

Login to post a comment