Exemplo n.º 1
0
 private static RebrandlyException BuildInvalidResponseException(RebrandlyResponse response)
 {
     return(new RebrandlyException(response.StatusCode, $"Invalid response object from API: \"{response.Content}\"")
     {
         RebrandlyResponse = response,
     });
 }
Exemplo n.º 2
0
        private static T ProcessResponse <T>(RebrandlyResponse response) where T : IRebrandlyEntity
        {
            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw BuildInvalidResponseException(response);
            }

            T obj;

            try
            {
                obj = RebrandlyEntity.FromJson <T>((response.Content.StartsWith("[")) ? @"{""data"":" + response.Content + "}" : response.Content);
            }
            catch (Newtonsoft.Json.JsonException)
            {
                throw BuildInvalidResponseException(response);
            }

            return(obj);
        }