question

jonathanjarri avatar image
jonathanjarri asked

How to properly handle errors in Cloud Scripts

Hello everyone,

I'm currently creating a lot of cloud scripts for my needs and I'm currently wondering how am I supposed to properly handle errors. I've read this page, and I already use exceptions (throw new Excepetion) when something got wrong, but what I obtain is a ScriptExecutionError without any error code, instead of a classic PlayFabError.


Do you have a method to easily send a kind of PlayFabError from a custom Cloud Script?

CloudScript
5 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.

jital avatar image jital ♦ commented ·

Hello,

The ScriptExecutionError is an error returned from the ExecuteCloudScript API call, so these errors need to be handled in your engine code. Inside the ScriptExecutionError contains an error code and name so using that, you should be able to diagnose your issue.

0 Likes 0 ·
jonathanjarri avatar image jonathanjarri jital ♦ commented ·

Thank you for your answer jitai, I'm already using the error code from the ScriptExecutionError, the point is I don't know how to set it from the Cloud Script, I always got a JavascriptException. Do you know how to do that?

0 Likes 0 ·
jital avatar image jital ♦ jonathanjarri commented ·

The ScriptExecutionError isn't something you can catch in the Cloudscript. It's an error that is thrown when you as a result of a ExecuteCloudScript call. You would have to catch this error in the SDK you are using.

Once the error is caught in your SDK code, you will be able to view the error code and investigate further.

Where are you calling your Cloudscript from?

0 Likes 0 ·
Show more comments

1 Answer

·
jonathanjarri avatar image
jonathanjarri answered

I've contacted the PlayFab support and the short answer is that you basically have two options:

- Call log.error() and then read the error information from the Logs array

- Return an error object and read it from the FunctionResult

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.