private async Task <T> GetInternal <T>(string url, string instanceName = Settings.DEFAULT_SERVICE_NAME) where T : class
{
var response = await GetRaw(url, instanceName).ConfigureAwait(false);
Console.WriteLine($"{response.RequestMessage.Method} - {url} - {(int) response.StatusCode}");
//for now
if (response.StatusCode == HttpStatusCode.NotFound || response.StatusCode == HttpStatusCode.ServiceUnavailable)
{
await Task.Delay(1000).ConfigureAwait(false);
return(null);
}
if (response.StatusCode != HttpStatusCode.OK)
{
throw new InvalidOperationException($"Call failed: {(int) response.StatusCode} - {response.ReasonPhrase}");
}
using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
{
var serializer = JsonSerializer.Create(serializerSettings);
return(serializer.Deserialize <T>(new JsonTextReader(new StreamReader(stream))));
}
}