Improve error logging

This commit is contained in:
WarmUpTill 2023-09-09 01:38:35 +02:00 committed by WarmUpTill
parent 03bb1fd089
commit cbd459b0a5

View File

@ -20,6 +20,12 @@ RequestResult SendGetRequest(const std::string &uri, const std::string &path,
httplib::Client cli(uri);
auto headers = getTokenRequestHeaders(token);
auto response = cli.Get(path, params, headers);
if (!response) {
auto err = response.error();
blog(LOG_INFO, "%s failed - %s", __func__,
httplib::to_string(err).c_str());
return {};
}
RequestResult result;
result.status = response->status;
if (response->body.empty()) {
@ -39,6 +45,12 @@ RequestResult SendPostRequest(const std::string &uri, const std::string &path,
auto json = obs_data_get_json(data);
std::string body = json ? json : "";
auto response = cli.Post(path, headers, body, "application/json");
if (!response) {
auto err = response.error();
blog(LOG_INFO, "%s failed - %s", __func__,
httplib::to_string(err).c_str());
return {};
}
RequestResult result;
result.status = response->status;
if (response->body.empty()) {
@ -58,6 +70,12 @@ RequestResult SendPatchRequest(const std::string &uri, const std::string &path,
auto json = obs_data_get_json(data);
std::string body = json ? json : "";
auto response = cli.Patch(path, headers, body, "application/json");
if (!response) {
auto err = response.error();
blog(LOG_INFO, "%s failed - %s", __func__,
httplib::to_string(err).c_str());
return {};
}
RequestResult result;
result.status = response->status;
if (response->body.empty()) {