public static string HandlePotentialQuandlError(System.Exception e, bool reThrow = true, Dictionary <string, string> additionalData = null) { // If it's detected as a quandl error handle it but don't send out sentry message. if (e.GetType() == typeof(QuandlErrorBase)) { return(HandleQuandlError((QuandlErrorBase)e, reThrow, additionalData)); } var innerException = e.InnerException; if (innerException != null && innerException.GetType() == typeof(QuandlErrorBase)) { QuandlErrorBase exBase = (QuandlErrorBase)e.InnerException.GetBaseException(); CheckNoApiKey(exBase.ErrorCode); return(HandleQuandlError((QuandlErrorBase)innerException, reThrow, additionalData)); } // We couldn't figure out how to handle it. Log and explode. Logger.log(e, additionalData); if (reThrow) { throw e; } return(null); }
private static async Task <HttpResponseMessage> RetrieveResponseWithRetries(HttpClient client, string relativeUrl, CancellationToken token, int remainingRetries = MaxHTTPRequestRetries) { var resp = await client.GetAsync(relativeUrl, token).ConfigureAwait(false); // Data fetching failed. There are retries remaining. if ((int)resp.StatusCode >= 500 && remainingRetries > 0) { await Task.Delay(MaxHTTPRequestTimeout); return(await RetrieveResponseWithRetries(client, relativeUrl, token, remainingRetries - 1)); } // The server returned an error and there are no retries remaining. else if ((int)resp.StatusCode >= 500) { var data2 = await resp.Content.ReadAsStringAsync(); var errorData = JsonConvert.DeserializeObject <QuandlError>(data2, JsonSettings()); var error = new QuandlErrorBase(resp.StatusCode, errorData.Code, errorData.Message); Logger.log(error, new Dictionary <string, string>() { { "APIKey", QuandlConfig.ApiKey }, { "RequestUrl", relativeUrl } } ); MessageBox.Show(Locale.English.ApiExperiencingIssues); throw error; } return(resp); }
public static string HandleQuandlError(QuandlErrorBase e, bool reThrow = true, Dictionary <string, string> additionalData = null) { if (!string.IsNullOrWhiteSpace((e).ErrorCode)) { StatusBar.AddException(e); return(e.Message); } // We couldn't figure out how to handle it. Log it. Logger.log(e, additionalData); if (reThrow) { throw e; } return(null); }