Manage connection errors: print and return 1

This commit is contained in:
King_DuckZ 2020-08-16 13:54:26 +01:00
parent 2d62b44ebc
commit 1c911f36b0

View file

@ -21,6 +21,24 @@
#include "evloop.hpp"
#include "app_config.hpp"
#include <iostream>
#include <restc-cpp/error.h>
namespace {
void print_ping(oro::Api& oro_api) {
auto ping = oro_api.ping();
std::cout << "date: " << ping.first.date << '\n';
std::cout << "rate limit: " << ping.first.rate_limit << '\n';
std::cout << "remaining: " << ping.first.rate_limit_remaining << '\n';
std::cout << "reset: " << ping.first.rate_limit_reset << '\n';
std::cout << "retry after: " << ping.first.retry_after << '\n';
std::cout << "server: " << ping.first.server << '\n';
std::cout << "-----\n";
std::cout << "timestamp: " << ping.second.generation_timestamp << '\n';
std::cout << "answer: " << ping.second.message << '\n';
std::cout << "version: " << ping.second.version << '\n';
}
} //unnamed namespace
int main(int argc, char* argv[]) {
if (2 != argc) {
@ -28,28 +46,24 @@ int main(int argc, char* argv[]) {
return 2;
}
oro::Api oro_api(duck::g_base_url, argv[1], "RESTC_CPP", "Testing");
auto ping = oro_api.ping();
try {
oro::Api oro_api(duck::g_base_url, argv[1], "RESTC_CPP", "Testing");
print_ping(oro_api);
std::cout << "date: " << ping.first.date << '\n';
std::cout << "rate limit: " << ping.first.rate_limit << '\n';
std::cout << "remaining: " << ping.first.rate_limit_remaining << '\n';
std::cout << "reset: " << ping.first.rate_limit_reset << '\n';
std::cout << "retry after: " << ping.first.retry_after << '\n';
std::cout << "server: " << ping.first.server << '\n';
std::cout << "-----\n";
std::cout << "timestamp: " << ping.second.generation_timestamp << '\n';
std::cout << "answer: " << ping.second.message << '\n';
std::cout << "version: " << ping.second.version << '\n';
duck::AppConfig app_conf;
oro::OriginsDB db(app_conf.db_path());
duck::test(
&oro_api,
&db,
app_conf.fetch_extra_delay(),
app_conf.worker_threads()
);
duck::AppConfig app_conf;
oro::OriginsDB db(app_conf.db_path());
duck::test(
&oro_api,
&db,
app_conf.fetch_extra_delay(),
app_conf.worker_threads()
);
}
catch (const restc_cpp::CommunicationException& err) {
std::cerr << "Communication with server \"" << duck::g_base_url <<
"\" failed: " << err.what() << '\n';
return 1;
}
/*
{