diff --git a/src/oro/api_nap_exception.cpp b/src/oro/api_nap_exception.cpp index 3f2bbd8..9d9b384 100644 --- a/src/oro/api_nap_exception.cpp +++ b/src/oro/api_nap_exception.cpp @@ -36,7 +36,7 @@ std::size_t append_to_char_arary (std::string_view in, char* out, std::size_t of ServerError::ServerError (const nap::HttpResponse& resp) : std::runtime_error( - std::string("Server replied: ") + std::to_string(resp.code) + " (" + + std::string("Server replied: ") + std::to_string(resp.code) + " (HTTP " + std::string(resp.http_ver) + ", \"" + std::string(resp.code_desc) + "\")" ), diff --git a/src/timer_oro_api.cpp b/src/timer_oro_api.cpp index 78453c0..7ec1332 100644 --- a/src/timer_oro_api.cpp +++ b/src/timer_oro_api.cpp @@ -22,6 +22,7 @@ # include "lzma.hpp" #endif #include "base64.hpp" +#include "magic_enum.hpp" #if defined(OROTOOL_WITH_RESTCCPP) # include #elif defined(OROTOOL_WITH_NAP) @@ -70,7 +71,7 @@ inline TimerOroApi::TimerOroApi ( template inline void TimerOroApi::fetch_data (oro::SourceFormat store_mode) { - int status_code = 200; + bool schedule_retry = false; try { auto results = invoke_api_func(oro_api(), store_mode); set_next_timer(results.header); @@ -96,8 +97,9 @@ inline void TimerOroApi::fetch_data (oro::SourceFormat store_mode) { } #if defined(OROTOOL_WITH_RESTCCPP) catch (const restc_cpp::RequestFailedWithErrorException& err) { - status_code = err.http_response.status_code; + const int status_code = err.http_response.status_code; if (429 == err.http_response.status_code) { + schedule_retry = true; //server received too many requests, give up for now } else { @@ -106,10 +108,17 @@ inline void TimerOroApi::fetch_data (oro::SourceFormat store_mode) { } #elif defined(OROTOOL_WITH_NAP) catch (const oro::ServerError& err) { - status_code = err.error_code(); - if (429 == status_code) { - } - else { + const int status_code = err.error_code(); + switch (status_code) { + case 503: + std::cerr << "Server returned 503 during request for " << + magic_enum::enum_name(Op) << '\n'; + schedule_retry = true; + break; + case 429: + schedule_retry = true; + break; + default: throw; } } @@ -134,7 +143,7 @@ inline void TimerOroApi::fetch_data (oro::SourceFormat store_mode) { #endif m_retries_left = error_retries(); - if (429 == status_code) { + if (schedule_retry) { oro::Header head; head.date.ts = std::chrono::time_point_cast(std::chrono::system_clock::now()); head.rate_limit = 1;