Hello!
I'm experiencing some trouble with cloudscript.
If I attempt to make a server call in cloudscript (such as GetSharedGroupData) on an non existing group (wich should return InvalidSharedGroupID) instead I get an error. Even If I use try catch the exception has no usefull info.
Is there any way to check for these errors in cloudscript?
such as:
var result=server.GetSharedGroupData({bla bla}); if(result.code==400){ something? } Kind Regards!
Answer by Brendan · Sep 16, 2016 at 02:11 AM
I'm not sure how you were using the try/catch, but that's specifically what I use to trap errors and process them in my own scripts. Using your example of GetSharedGroupData, if you were to run this:
handlers.test = function (args, context) { try { var result = server.GetSharedGroupData({ SharedGroupId: args.SharedGroup }); log.info(result); } catch(e) { var msg = "Error: " + JSON.stringify(e); log.info(msg); } }
What you would see is that the error (e) coming into the catch has the error details. Specifically, I passed in a fake Shared Group Data, and the error object contained the following:
{ "cloudScriptErrorCode": "CloudScriptAPIRequestError", "stack": "Error\\n at Object.__playfab_internal_v2.server_request (Script Document:165:24)\\n at Object.server.GetSharedGroupData (Script Document:520:75)\\n at handlers.test (5F4-main.js:5:25)\\n at Object.__playfab_internal_v2.invokeFunction (Script Document:110:33)", "apiErrorInfo": { "api": "/Server/GetSharedGroupData", "request": { "SharedGroupId": "fake" }, "result": null, "apiError": { "code": 400, "status": "BadRequest", "error": "InvalidSharedGroupId", "errorCode": 1088, "errorMessage": "InvalidSharedGroupId", "errorHash": null, "errorDetails": null } } }
So the cloudScriptErrorCode tells you what happened, while the apiErrorInfo (in this case) contains all the details. So e.apiErrorInfo.apiError.error was "InvalidSharedGroupId".
We'll have more debugging options available as soon as we can of course, including better docs walking you through this sort of thing.
Thank you so much!
My problem was that I wasn't stringyfing the catched error thinking that it only returned apiError (silly me)
Hi Brendan,
All errors in CloudScript have the same structure?
Like :
{ "cloudScriptErrorCode": "...", "stack": "...", "apiErrorInfo": { "api": "/Server/...", "request": { "...": "..." }, "result": null, "apiError": { "code": ..., "status": "...", "error": "...", "errorCode": ..., "errorMessage": "...", "errorHash": ..., "errorDetails": ... } } }
Thanks in advance!
They'll all follow that basic format, though if the error wasn't the result of a call to a Server API method, you won't have the apiErrorInfo.