Esempio n. 1
0
        void OnCustomError(HttpWebRequestInfo reqInfo, string customStatusCode)
        {
            if (string.IsNullOrEmpty(customStatusCode))
            {
                Debug.LogErrorFormat("Request {0} has no custom status code", reqInfo.Host);
            }
            else
            {
                Debug.LogErrorFormat("Request {0} has custom error: {1} ", reqInfo.Host, customStatusCode);

                var codes = customStatusCode.Split(';');
                if (codes.Length > 1)
                {
                    reqInfo.OnCustomStatusError(reqInfo, codes[0], codes[1]);
                }
                else
                {
                    reqInfo.OnCustomStatusError(reqInfo, codes[0], "");
                }
            }
        }
Esempio n. 2
0
        void OnSucess(HttpWebRequestInfo request, string jsonData)
        {
            object o;

            try
            {
                if (request.ReturnRawJsonStr)
                {
                    o = jsonData;
                }
                else
                {
                    o = JsonUtilNet.Deserialize(jsonData, request.ReturnType);
                    Debug.LogFormat("receive data from {0} \n {1}", request.Host, jsonData);
                }
            }
            catch (Exception e)
            {
                Debug.LogError("json deserialize failed. data: \n" + jsonData);
                Debug.LogException(e);
                request.OnCustomStatusError(request, "", "服务器返回数据错误");
                return;
            }

            try
            {
                if (Validator.ValidateObject(o))
                {
                    request.OnResponse.DynamicInvoke(o);
                }
                else
                {
                    request.OnCustomStatusError(request, "", "服务器返回数据错误");
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }