question

felipeclaude avatar image
felipeclaude asked

CloudScript Errors on server api calls

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!
apisCloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

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.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

felipeclaude avatar image felipeclaude commented ·

Thank you so much!

My problem was that I wasn't stringyfing the catched error thinking that it only returned apiError (silly me)

0 Likes 0 ·
alexm avatar image alexm commented ·

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!

0 Likes 0 ·
brendan avatar image brendan alexm commented ·

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.

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.