Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by felipeclaude · Sep 16, 2016 at 02:03 AM · CloudScriptapis

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!
Comment
agniesportsyt

People who like this

1 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

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.

Comment
felipeclaude

People who like this

1 Show 3 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image felipeclaude · Sep 16, 2016 at 12:52 PM 0
Share

Thank you so much!

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

avatar image alexm · Jul 06, 2018 at 02:28 PM 0
Share

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!

avatar image Brendan ♦♦ alexm · Jul 06, 2018 at 08:27 PM 1
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    [Cloud Script]Change User display name 1 Answer

    In CloudScript: can I access Days, Hours, Minutes from a date? 1 Answer

    Using Custom Tags with Email verification rule 1 Answer

    Best solution for accessing TITLE INTERNAL DATA 1 Answer

    CloudScript check user VC before subtracting? 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges