Error() public static method

public static Error ( string msg, bool fatal = false ) : void
msg string
fatal bool
return void
Exemplo n.º 1
0
 // Callback
 static void OnLoginByName(JSON result)
 {
     try
     {
         Crown.instance.userId   = result.GetField("userId").str;
         Crown.instance.userKey  = result.GetField("userKey").str;
         Crown.instance.userSpot = result.GetField("spot").str;
     }
     catch
     {
         Crown.Error("Login error, data not found");
     }
 }
Exemplo n.º 2
0
    /*
     * Network request (send data and get result)
     */
    public static IEnumerator Request(string function, JSON parameters = null, CrownCallbackJSON callback = null, CrownCallbackJSON internalCallback = null)
    {
        string url = instance.serverURL;

        Crown.Log("Server request " + function);

        // Create www post
        WWWForm form = new WWWForm();

        // Add platform, function and parameters
        form.AddField("function", function);
        form.AddField("parameters", parameters.print());

        // Add user data
        form.AddField("userId", instance.userId);
        form.AddField("userKey", instance.userKey);
        form.AddField("userSpot", instance.userSpot);

        // Download
        WWW www = new WWW(url, form);

        yield return(www);

        // Get request
        if (www.error == null)
        {
            // Try to get JSON DATA
            JSON result = null;
            try
            {
                result = new JSON(www.text);
                Crown.Log("Request result: " + result.print());
            }
            catch
            {
                Crown.Error("Server wrong data: " + www.text);
            }

            // Check for server errors
            if (result["error"] != null)
            {
                Crown.Error("Server error: " + result["error"], true);
            }
            // Get json array
            else if (result["data"] != null)
            {
                if (callback != null)
                {
                    callback(result["data"]);
                }
                if (internalCallback != null)
                {
                    internalCallback(result["data"]);
                }
            }
            else
            {
                Crown.Error("Server return's null result", true);
            }
        }
        else
        {
            Crown.Error("Request error " + url + ", www error: " + www.error, true);
        }
    }