예제 #1
0
        public static void BuildResponseObjectOnFailure(CallbackResponse response, UnityWebRequest www)
        {
            if (www.responseCode == 404L)
                response.Status = CallBackResult.NotFound;
            else if (www.responseCode == 409L)
                response.Status = CallBackResult.ResourceExists;
            else
                response.Status = CallBackResult.Failure;

            string errorMessage = www.error;
            if (errorMessage == null && www.downloadHandler != null && !string.IsNullOrEmpty(www.downloadHandler.text))
                errorMessage = www.downloadHandler.text;
            else
                errorMessage = Globals.ErrorOccurred;

            Exception ex = new Exception(errorMessage);
            response.Exception = ex;
        }
        private IEnumerator GetStuffArray <T>(string url, Action <CallbackResponse <T[]> > callback)
        {
            using (UnityWebRequest www = Utilities.BuildMessageOfTheDayAPIWebRequest
                                             (url, HttpMethod.Get.ToString(), null))
            {
                yield return(www.Send());

                if (Globals.DebugFlag)
                {
                    Debug.Log(www.responseCode);
                }
                var response = new CallbackResponse <T[]>();
                if (Utilities.IsWWWError(www))
                {
                    if (Globals.DebugFlag)
                    {
                        Debug.Log(www.error);
                    }
                    Utilities.BuildResponseObjectOnFailure(response, www);
                }
                else
                {
                    try
                    {
                        T[] data = JsonHelper.GetJsonArray <T>(www.downloadHandler.text);
                        response.Result = data;
                        response.Status = CallBackResult.Success;
                    }
                    catch (Exception ex)
                    {
                        response.Status    = CallBackResult.DeserializationFailure;
                        response.Exception = ex;
                    }
                }
                callback(response);
            }
        }
예제 #3
0
 public static void BuildResponseObjectOnException(CallbackResponse response, Exception ex)
 {
     response.Status = CallBackResult.LocalException;
     response.Exception = ex;
 }