question

Spektra Games avatar image
Spektra Games asked

​The Exceptions Are Not Returning To Client from Azure Function

On Azure side, when any exception occured in function, then the exceptions details are not returning to client. The client just see : "/CloudScript/ExecuteFunction: Invocation of cloud script function FUNCTION_NAME failed". This also happening for my custom exception on azure function server(Like: throw new Exception("blablabla");) Can I return errors to client as PlayFab error? Because I don't want to send errors to client as a message in resulted successful function

CloudScript
10 |1200

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

JayZuo avatar image
JayZuo answered

It would be hard to return Azure Function errors to client as PlayFab error. But it's possible to return the exception info to client with adding a try-catch as the following:

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace My.Functions
{
  public static class MyFunction
  {
    [System.Serializable]
    struct Response
    {
      public byte code;
      public string message;
    }

    [FunctionName("MyFunction")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
      try
      {
        throw new Exception("blablabla");
        return new OkObjectResult(new Response{
          code = 0,
          message = "All good"
        });
      } 
      catch (Exception e)  
      {
        return new OkObjectResult(new Response{
          code = 1,
          message = $"Something went wrong: {e.Message}"
        });
      }
    }
  }
}

Please note, we still need to return OkObjectResult for the exception as if the Azure Function returns a status code not in the Successful range (200-299), "CloudScript/ExecuteFunction" will return the "CloudScriptAzureFunctionsHTTPRequestError" as you've seen.

10 |1200

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

Seth Du avatar image
Seth Du answered

Currently it is not supported. There can be workarounds, but it is not easy to get instant information. Feel free to send a thread on the Feature Request forum --https://community.playfab.com/spaces/24/index.html.

10 |1200

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

Chris Fitzpatrick avatar image
Chris Fitzpatrick answered
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.