Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Unity WebGL Firebase: Request Failed![0] when loading data

Discussion in 'Scripting' started by Milan_G043, Apr 26, 2024.

  1. Milan_G043

    Milan_G043

    Joined:
    Apr 26, 2024
    Posts:
    1
    I have a function that downloads and shows data stored in a JSON file from Firebase. It downloads data from a company, so the user fills in a pincode and then it downloads the data from that company.

    I tested this in Unity and it works like it should, it also works on webgl. However there is one company that is quite large and has a lot of data, again in Unity it works without any problems, it loads and shows the data. But on Webgl I get the error "Request Failed![0]" 2 times, 1 at around 60% and 1 at around 90%.

    There are no "CORS" errors and I also tried increasing the timeout but with no results. I suspect it has something to do with the size of the data, but I am not sure.

    I tested on multiple different browsers as well with no result.

    here is the part of code that downloads the data:


    Code (CSharp):
    1.  
    2. public static void GetCompanyReport(UnityAction<ReportRequest> callback = null)
    3. {
    4.     AuthHandler.GetIdToken(tokenCallback =>
    5.     {
    6.         if (tokenCallback.IsSuccess)
    7.         {
    8.             HTTPRequest request = new HTTPRequest(new System.Uri(FirebaseConfig.Instance.DatabaseURL + @"/Test/TestData"), HTTPMethods.Post, (req, response) =>
    9.             {
    10.                 Debug.Log("Reached Code in GetCompanyReport Block 1");
    11.                 if (response.IsSuccess)
    12.                 {
    13.                     Debug.Log("Reached Code in GetCompanyReport Block 2");
    14.  
    15.                     Debug.Log("Reached Code in GetCompanyReport Block 3");
    16.                     ReportRequest resp = JsonUtility.FromJson<ReportRequest>(response.DataAsText);
    17.                     Debug.Log("Request Finished! Text received: " + response.DataAsText);
    18.                     resp.IsSuccess = true;
    19.                     callback?.Invoke(resp);
    20.                 }
    21.                 else
    22.                 {
    23.                     bool keepGoing = NetworkErrorHandler.HandleError(response.StatusCode);
    24.                     Debug.LogError("Request Failed![" + response.StatusCode + "]" + response.Message);
    25.  
    26.                     if (keepGoing)
    27.                     {
    28.                         ServerManager.NetworkResponse resp = ServerManager.NetworkResponse.Fail;
    29.                         resp.errorcode = response.StatusCode;
    30.                         Debug.LogError("Request Failed![" + response.StatusCode + "]" + response.Message);
    31.                         callback?.Invoke(resp as ReportRequest);
    32.                     }
    33.                 }
    34.             });
    35.             Debug.Log("Reached code in GetCompanyReport Block 4");
    36.             request.Timeout = TimeSpan.FromSeconds(500);
    37.             Debug.Log("Reached code in GetCompanyReport Block 5");
    38.  
    39.  
    40.             request.AddHeader("Content-Type", "application/json");
    41.  
    42.             var data = new BaseNetworkRequestData().SetPincode(CurrentCompany.publicdata.pincode).SetUserData().SetPincode();
    43.             string jsondata = JsonUtility.ToJson(data);
    44.             request.RawData = System.Text.Encoding.UTF8.GetBytes(jsondata);
    45.             Debug.Log(jsondata);
    46.             request.Send();
    47.         }
    48.     });
    49. }