question

My Game Studio avatar image
My Game Studio asked

Cloudscript API

Hello,

I'm trying to figure out why some API calls (serverside server object) return a fully qualified json object (with .code, .status, .Data) and some only return a subset of data?

 

Example server.GrantCharacterToUser returns just the CharacterId, nothing else of the normal REST API - This seems mix/matched as some calls do return full objects that can be used for error handling

 

Any tips on how to find what objects are what?

10 |1200

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

My Game Studio avatar image
My Game Studio answered

http://cloudscript.playfab.com/ does not document any exception states. Can you please provide a complete example that correctly implements cloudscript side error handling? None of the samples have any mentions to exceptions

10 |1200

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

Hamza Lazaar avatar image
Hamza Lazaar answered

@paultech: yes I saw the Photon Integration sample, unfortunately it does not expose much and people ask for how to load/save games which is not as trivial as it seems considering PlayFab limits and CloudScript status. Now that I work with Exit Games, my task is to help others make their games easily using Photon.

@Brendan: an example please, how to handle errors. I'm guessing try/catch is a must. Is the error object always thrown/returned is of type 'PlayFabError' or 'PlayFabAPIError' or 'JavaScriptError' or something else?

10 |1200

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

brendan avatar image
brendan answered

We'll be updating the Cloud Script docs and providing an example that shows more complete error handling as soon as we can - I just spoke with the Tools team lead about this, and he's very much aware of the need.

To quickly get you the info you need:

Yes, any error response to a Server API method is an exception. As this thread has highlighted (and I'm going to be working with our engineering team on this as a priority), the error return if you do nothing else is not useful, as it is missing parts of the error specifics. Instead, I would recommend using a try/catch, similar to this:

handlers.GetMessages = function(args)
{
  var messageGroupId = currentPlayerId + "_messages";
  var returnvalue = {};
  var messageData;

  try
  {
    messageData = server.GetSharedGroupData({"SharedGroupId" : messageGroupId});
  }
  catch(error)
  {
    log.info(error);
  }

  returnvalue["messages"] = messageData;

  return returnvalue;
};

In this case, I'm handling the error outside the Cloud Script, via the log info returned. If you wanted to handle it inside the Cloud Script, then yes, the error response info contains the elements I mentioned earlier (error, errorCode, errorMessage, and errorDetails if necessary). So in my case, since I haven't actually created this Shared Group Data in my title, the response is:

{
  "code": 200,
  "status": "OK",
  "data": {
    "ActionId": "GetMessages",
    "Version": 1,
    "Revision": 61,
    "Results": {},
    "ResultsEncoded": "{}",
    "ActionLog": "info : {\"code\":400,\"status\":\"BadRequest\",\"error\":\"InvalidSharedGroupId\",\"errorCode\":1088,\"errorMessage\":\"InvalidSharedGroupId\"}\n",
    "ExecutionTime": 0.9239776
  }
}

10 |1200

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

Hamza Lazaar avatar image
Hamza Lazaar answered

This explains why the object caught does not contain "name", "message" nor "stack" properties. I always thought a JavaScript custom Error object should "inherit" from base "Error" object and have at least those properties.

And I think the error object type is 'PlayFabAPIError'.

Thanks for the example Brendan, I feel better now and sorry if I sound rude sometimes.

10 |1200

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

brendan avatar image
brendan answered

Not a problem at all, Hamza. We need people to tell us when we're wrong.  :)

10 |1200

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

Hamza Lazaar avatar image
Hamza Lazaar answered

@My Game Studio (ex. paultech):

can you tell me how do you handle errors now after the updates?

The thrown error has no particular type, it's not `PlayFabError` nor `PlayFabAPIError`, it's just an 'object'.

What I'm thinking of is to use this workaround to make the difference between PlayFab errors and the other types of JavaScript errors:

```try {

} catch (e) {

if (e.errorCode === undefined) { 

// JavaScript error

} else {

// PlayFab error

}

}```

10 |1200

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

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.