forked from ShuriZma/suyu
1
0
Fork 0

web_service: web_backend: Handle socket errors with GenericRequest.

- Fixes a shutdown crash when we try to submit telemetry if there is a service issue.
This commit is contained in:
bunnei 2020-10-28 17:18:33 -07:00
parent 475d46bb64
commit 156556ddd2
1 changed files with 11 additions and 0 deletions

View File

@ -65,6 +65,17 @@ struct Client::Impl {
if (cli == nullptr) { if (cli == nullptr) {
cli = std::make_unique<httplib::Client>(host.c_str()); cli = std::make_unique<httplib::Client>(host.c_str());
} }
if (!cli->is_valid()) {
LOG_ERROR(WebService, "Client is invalid, skipping request!");
return {};
}
if (!cli->is_socket_open()) {
LOG_ERROR(WebService, "Failed to open socket, skipping request!");
return {};
}
cli->set_connection_timeout(TIMEOUT_SECONDS); cli->set_connection_timeout(TIMEOUT_SECONDS);
cli->set_read_timeout(TIMEOUT_SECONDS); cli->set_read_timeout(TIMEOUT_SECONDS);
cli->set_write_timeout(TIMEOUT_SECONDS); cli->set_write_timeout(TIMEOUT_SECONDS);