protected async Task <T> PostJsonAsync <T>(string requestUri, string json) { HttpResponseMessage response; string responseContent = null; var content = new StringContent(json, Encoding.UTF8, "application/json"); try { response = await client.PostAsync(requestUri, content).ConfigureAwait(false); responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); response.EnsureSuccessStatusCode(); } catch (HttpRequestException) { RippleRestErrorResponse r; if (RippleRestErrorResponse.TryParse(responseContent, out r)) { throw new RippleRestErrorException(r); } else { throw; } } return(JsonConvert.DeserializeObject <T>(responseContent, serializerSettings)); }
public static bool TryParse(string json, out RippleRestErrorResponse e) { if (string.IsNullOrEmpty(json)) { e = null; return(false); } var settings = new JsonSerializerSettings() { MissingMemberHandling = MissingMemberHandling.Error, ContractResolver = new CustomContractResolver() }; try { e = JsonConvert.DeserializeObject <RippleRestErrorResponse>(json, settings); } catch (JsonException) { e = null; return(false); } return(true); }
protected async Task <T> GetJsonAsync <T>(string requestUri) { HttpResponseMessage response = null; string responseContent = null; try { response = await client.GetAsync(requestUri).ConfigureAwait(false); responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); response.EnsureSuccessStatusCode(); } catch (HttpRequestException) { RippleRestErrorResponse r; if (RippleRestErrorResponse.TryParse(responseContent, out r)) { throw new RippleRestErrorException(r); } else { throw; } } return(JsonConvert.DeserializeObject <T>(responseContent, serializerSettings)); }
/// <summary> /// Initializes a new instance of the <see cref="RippleRestErrorException"/> class. /// </summary> /// <param name="message"></param> public RippleRestErrorException(RippleRestErrorResponse response) : base(response.Message) { ErrorResponse = response; }