If I stringify it, then it has ugly escape characters and would need to be parsed.
Ideally we would have more control over the entire response error object. Adding keys
{
"@class": ".GameSparksErrorResponse",
"error": {
"message": "You do not have 100 money.",
"code" : "MONEY_CANNOT_AFFORD",
"data" : {"current_money" : 10}
},
"message": "you do not have 100 money.",
"code" : "MONEY_CANNOT_AFFORD",
"data" : {"current_money" : 10}
}
Best Answer
C
Customer Support
said
over 6 years ago
Hi Christopher,
This new method has now been added. It's called Spark.exit(). There is a brief example of it's usage in this thread. If you have nay further questions just let us know.
No you can't do this with a throw. You could do this by setting a ScriptError in your script. You could use something like the following and replace the keys and values with whatever suits
We will be implementing a new GameSparks method in the coming months that can be used to exit a Cloud Code script at a particular point. At that stage I'd recommend not using throw and switching to that method for all future use. If you have any further questions just let me know.
Thanks,
Liam
C
Christopher Stewart
said
over 6 years ago
Thanks! The new method, will it allow custom error responses? I tried setScriptError but it doesn't show up when used with throw.
Customer Support
said
over 6 years ago
Hi Christopher,
Apologies, I missed your response. I'll find this out and get back to you asap.
Thanks,
Liam
Customer Support
said
over 6 years ago
Hi Christopher,
The new method will be used in conjunction with setScriptError. You will use a combination of both to stop the execution of a Cloud Code script and set an error to display in the response when this happens. I'll update the thread when this new method has been released.
Thanks,
Liam
1 person likes this
Customer Support
said
over 6 years ago
Answer
Hi Christopher,
This new method has now been added. It's called Spark.exit(). There is a brief example of it's usage in this thread. If you have nay further questions just let us know.
Christopher Stewart
Hi,
The use of of throw in Cloud Code allows us to stop execution and return a string. Is there a way to add more fields to the returned error?
If we throw JSON it shows up as Object in the response.
If I stringify it, then it has ugly escape characters and would need to be parsed.
Ideally we would have more control over the entire response error object. Adding keys
Hi Christopher,
This new method has now been added. It's called Spark.exit(). There is a brief example of it's usage in this thread. If you have nay further questions just let us know.
Thanks,
Liam
1 person has this question
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi Christopher,
No you can't do this with a throw. You could do this by setting a ScriptError in your script. You could use something like the following and replace the keys and values with whatever suits
We will be implementing a new GameSparks method in the coming months that can be used to exit a Cloud Code script at a particular point. At that stage I'd recommend not using throw and switching to that method for all future use. If you have any further questions just let me know.
Thanks,
Liam
Christopher Stewart
Thanks! The new method, will it allow custom error responses? I tried setScriptError but it doesn't show up when used with throw.
Customer Support
Hi Christopher,
Apologies, I missed your response. I'll find this out and get back to you asap.
Thanks,
Liam
Customer Support
Hi Christopher,
The new method will be used in conjunction with setScriptError. You will use a combination of both to stop the execution of a Cloud Code script and set an error to display in the response when this happens. I'll update the thread when this new method has been released.
Thanks,
Liam
1 person likes this
Customer Support
Hi Christopher,
This new method has now been added. It's called Spark.exit(). There is a brief example of it's usage in this thread. If you have nay further questions just let us know.
Thanks,
Liam
1 person likes this
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics