/// <summary> /// 检查返回的文本,如果是异常信息,则抛出 /// </summary> /// <param name="responseText"></param> public static void CheckResponseText(string responseText) { QQLoginConnectionException exception = QQLoginConnectionException.FromResponseText(responseText); if (exception != null) { throw exception; } }
/// <summary> /// 从响应结果中返回异常类。如果不是错误信息,则返回NULL /// </summary> /// <param name="responseText"></param> /// <returns></returns> public static QQLoginConnectionException FromResponseText(string responseText) { string json = QQLoginConnectionManager.GetResponseJsonString(responseText); QQLoginConnectionException result = null; if (json.IsNotEmpty()) { string error = null; string description = null; string message = null; Dictionary <string, object> data = JSONSerializerExecute.Deserialize <Dictionary <string, object> >(json); if (data.ContainsKey("error")) { error = data.GetValue("error", string.Empty); description = data.GetValue("error_description", string.Empty); message = string.Format("Error: {0}, Description: {1}", error, description); } else { error = data.GetValue("ret", 0).ToString(); if (error != "0") { error = data.GetValue("ret", 0).ToString(); description = data.GetValue("msg", string.Empty); message = string.Format("Error: {0}, Description: {1}", error, description); } } if (message.IsNotEmpty()) { result = new QQLoginConnectionException(message); result.ErrorCode = error; result.ErrorDescription = description; } } return(result); }
/// <summary> /// 从响应结果中返回异常类。如果不是错误信息,则返回NULL /// </summary> /// <param name="responseText"></param> /// <returns></returns> public static QQLoginConnectionException FromResponseText(string responseText) { string json = QQLoginConnectionManager.GetResponseJsonString(responseText); QQLoginConnectionException result = null; if (json.IsNotEmpty()) { string error = null; string description = null; string message = null; Dictionary<string, object> data = JSONSerializerExecute.Deserialize<Dictionary<string, object>>(json); if (data.ContainsKey("error")) { error = data.GetValue("error", string.Empty); description = data.GetValue("error_description", string.Empty); message = string.Format("Error: {0}, Description: {1}", error, description); } else { error = data.GetValue("ret", 0).ToString(); if (error != "0") { error = data.GetValue("ret", 0).ToString(); description = data.GetValue("msg", string.Empty); message = string.Format("Error: {0}, Description: {1}", error, description); } } if (message.IsNotEmpty()) { result = new QQLoginConnectionException(message); result.ErrorCode = error; result.ErrorDescription = description; } } return result; }