private async Task HandleErrors(HttpResponseMessage response) { var content = response.Content == null ? null : await response.Content.ReadAsStringAsync().ConfigureAwait(false); var apiError = ApiError.ParseOrDefault(content); if ((int)response.StatusCode == HttpStatusCodeTooManyRequests) { throw new RateLimitApiException(RateLimit.Parse(response.Headers)); } throw new ErrorApiException(response.StatusCode, apiError); }
/// <summary> /// Creates a new instance of the ApiInfo class. /// </summary> /// <param name="rateLimit">The current rate limit information.</param> /// <param name="serverTime">The current server time</param> public ApiInfo(RateLimit rateLimit, DateTimeOffset?serverTime) { RateLimit = rateLimit; ServerTime = serverTime; }
/// <summary> /// Creates a new instance of the ApiInfo class. /// </summary> /// <param name="rateLimit">The current rate limit information.</param> public ApiInfo(RateLimit rateLimit) : this(rateLimit, null) { }
public static ApiInfo Parse(HttpResponseHeaders headers) { RateLimit rateLimit = ParseRateLimit(headers); return(new ApiInfo(rateLimit)); }