private static void SetResponse(AnswerModel response, UnityWebRequest req) { #if UNITY_2017 if (req.isHttpError) #elif UNITY_5 if (req.isError) #endif { response.SetFields(HandleExceptionText(req.error, (HttpStatusCode)req.responseCode)); } #if UNITY_2017 else if (req.isNetworkError) { response.SetFields(HandleExceptionText(req.error, (HttpStatusCode)req.responseCode)); } #endif else { response.SetFields(new AnswerModel(req.downloadHandler.text)); } }
public static IEnumerator StartRequest(string url, object parameters, string contentType, bool forceUpdate, DataType type, AnswerModel response, string loadingPanelsKey) { forceUpdate = GetForceUpdate(type, forceUpdate); if (forceUpdate) { Extensions.ShowGameObjects(LoadingManager.GetPanelsByKey(loadingPanelsKey)); } while (GameController.PersistentDataPath == null) { yield return(null); } string parms = string.Empty; IEnumerator e = SerializeParameters(parameters); yield return(e); parms = e.Current as string; if (!forceUpdate) { string data = Extensions.LoadJsonData(type); if (!string.IsNullOrEmpty(data) || type == DataType.UserInfo) { response.SetFields(new AnswerModel(data)); } } if (response.StatusCode == 0) { forceUpdate = true; LoadingManager.PanelKeyToEnable = loadingPanelsKey; var req = CreateRequest(url, parms, contentType, LoginManager.Instance.Headers); yield return(SendRequest(req)); SetResponse(response, req); } if (NeedSave(response.StatusCode, forceUpdate, type)) { Extensions.SaveJsonDataAsync(type, response.Text); } }