question

Thomas Brown avatar image
Thomas Brown asked

How do we return an error from Azure Functions

Essentially I'm looking to throw an error / return an error so that when I execute an Azure Function in Unity using ExecuteFunction method, I get a return to the errorCallback with a custom error message.

It looks like the way to normally do this is by returning a BadObjectResult object in Azure Functions. While that does indeed execute the errorCallback function I'm not sure how to return any meaninful error message or data using that method.

It also looks like this question may have already been asked, but I don't think the answer really addresses the issue. See here.

Thanks in advance!

apis
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

·
Made Wang avatar image
Made Wang answered

To clarify, the errorCallBack of ExecuteFunction will only return when the API itself fails to call, which means it will only return these error messages.

If you need to return an error message during the execution of Azure Function Cloud Script, you can use try/catch and return it in OkObjectResult as the result of a successful call, refer to The Exceptions Are Not Returning To Client from Azure Function - Playfab Community.

1 comment
10 |1200

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

Thomas Brown avatar image Thomas Brown commented ·

I understand now, I forgot that PlayFab works in this manner. This is how I solved this issue on my end. Hopefully it helps someone!

https://gist.github.com/thsbrown/8701b49d9c51b17f403edf2e45f3e637

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.