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.
Answer by Sarah Zhang · Mar 12, 2020 at 06:31 AM
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"; }
And what about in the case of AddMembers? Does it also returns the NULL or Empty string in response?
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.
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.