question

Muhammad Roshaan Tariq avatar image
Muhammad Roshaan Tariq asked

Cloudscript returning NULL in Response

Hi,

I have used CloudScript for integrating Clan/Group System in my game. All Clans/Group functions are implemented on server side and I am using ExecuteCloudScript on client side to call these functions.

What I really want is that the CloudScript should return some proper response but what I get is just NULL (Please check screenshot I have attached)

here's my cloudcode:

handlers.joinGroup = function(args,context){
  var addMemberToGroup = {
      "Group":{
          "Id": args.groupID
      },
      "Members":[{
          "Id": args.userID,
          "Type": "title_player_account",
          "TypeString": "title_player_account"
      }],
      "RoleId": args.roleID
  };
  
  var response = entity.AddMembers(addMemberToGroup);
  return response;
};

and here's what I get in response

Now you see even though the cloudscript ran the function successfully but I didn't get a proper response to identify whether the function was a success or failure.

apissdksCloudScriptentities
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

·
Sarah Zhang avatar image
Sarah Zhang answered

API AddMembers or RemoveMembers would not return any data when it is requested successfully, but you can catch its error when it is called failed. Doing error handling on the clients and on CloudScript are both feasible. Please follow this documentation SDK error handling best practices if you want to handle errors on clients. If you want to get a “Success” string or error messages from the CloudScript function result, please try to add the following code in the function.

handlers.leaveGroupGenerateError = function (args, context) {
    var removeGroupMember = {
        "Group": {
            "Id": args.groupID
        },
        "Members": [{
            "Id": args.userID,
            "Type": "title_player_account",
            "TypeString": "title_player_account"
        }]
    };
    try {
        var response = entity.RemoveMembers(removeGroupMember);
    } catch (ex) {
        let errorMessage = ex.apiErrorInfo.apiError.errorMessage;
        return errorMessage;
    }
    return "Success";
}

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.

Muhammad Roshaan Tariq avatar image Muhammad Roshaan Tariq commented ·

@Sarah Zhang

And what about in the case of AddMembers? Does it also returns the NULL or Empty string in response?

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Muhammad Roshaan Tariq commented ·

Yes, it's an omission, I have modified the answer to add it.

In addition, you can test every PlayFab API on your own too. PlayFab provides the SDK for Postman which is an external REST API testing tool. This is one of the fastest ways to get started testing PlayFab. You can test the API via Postman before you call it on CloudScript, you can also test the CloudScript functions via API ExecuteEntityCloudScript and ExecuteCloudScript in the Postman.

0 Likes 0 ·
Muhammad Roshaan Tariq avatar image Muhammad Roshaan Tariq Muhammad Roshaan Tariq commented ·

@Sarah Zhang

Alright, thanks for clearing this up because I was trying to find why there isn't anything returning from the API when I run it using cloudscript.

0 Likes 0 ·

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.