public List <ValidOrErrorResponse <ValidType> > Deserialize(string response) { List <object> responseDeserialized; if (response[0] == '[') { responseDeserialized = JsonTools.DeserializeFromJson <List <object> >(response); } else { responseDeserialized = new List <object>(); responseDeserialized.Add(JsonTools.DeserializeFromJson <object>(response)); } List <ValidOrErrorResponse <ValidType> > output = new List <ValidOrErrorResponse <ValidType> >(); for (int i = 0; i < responseDeserialized.Count; i++) { try { ValidType validObject = ((JObject)responseDeserialized[i]).ToObject <ValidType>(); output.Add(new ValidOrErrorResponse <ValidType>(validObject)); } catch (Exception) { ErrorMessage errorObject = ((JObject)responseDeserialized[i]).ToObject <ErrorMessage>(); output.Add(new ValidOrErrorResponse <ValidType>(errorObject)); } } return(output); }
dynamic TryGetResponseDynamic(RestClient rc) { if (CheckResult(rc)) { string response = rc.GetResponseToString; return(JsonTools.DeserializeFromJson(response)); } throw new Exception("Unknown error."); }
bool CheckResult(RestClient rc) { if (rc.ResponseHasNoErrors()) { return(true); } else { ErrorMessage error = JsonTools.DeserializeFromJson <ErrorMessage>(rc.GetResponseToString); throw new ErrorMessageException(error.Code, error.Msg); } }
public List <T> Deserialize(string response) { List <T> responseDeserialized; if (response[0] == '[') { responseDeserialized = JsonTools.DeserializeFromJson <List <T> >(response); } else { responseDeserialized = new List <T>(); responseDeserialized.Add(JsonTools.DeserializeFromJson <T>(response)); } return(responseDeserialized); }
bool CheckResult(RestClient rc) { if (rc.ResponseHasNoErrors()) { return(true); } else if (rc.GetStatusCode == 400) { ErrorMessage error = JsonTools.DeserializeFromJson <ErrorMessage>(rc.GetResponseToString); throw new ErrorMessageException(error.Code, error.Msg); } else if (rc.GetStatusCode == 429) { throw new RateLimitException(429, "Rate limit, too many request.", true); } else if (rc.GetStatusCode == 418) { throw new RateLimitException(418, "Rate limit, too many request (ban ip).", isBan: true); } else { throw new RateLimitException(403, "Rate limit, too many weight (WPF error).", true); } }