DectrisSimplonClient: Avoid dereferencing null pointers in error handling

This commit is contained in:
2026-04-29 13:36:09 +02:00
parent 4878318c27
commit 03a7297cab
+12 -8
View File
@@ -54,10 +54,12 @@ void DectrisSimplonClient::SendDetectorCommand(SimplonDetectorCommand cmd) {
auto res = cli_cmd.Post(addr);
if (!res || res->status != httplib::StatusCode::OK_200) {
std::string err_msg = "Command failed " + key + "; HTTP " + std::to_string(res->status);
if (res && !res->body.empty())
err_msg += "; " + res->body;
std::string err_msg = "Command failed " + key;
if (res) {
err_msg += "; HTTP" + std::to_string(res->status);
if (!res->body.empty())
err_msg += "; " + res->body;
}
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, err_msg);
}
}
@@ -76,10 +78,12 @@ void DectrisSimplonClient::SetConfig(SimplonModule element, const std::string &k
auto res = cli_cmd.Post(addr, j.dump(), "application/json");
if (!res || res->status != httplib::StatusCode::OK_200) {
std::string err_msg = "Configure failed " + key + "; HTTP " + std::to_string(res->status);
if (res && !res->body.empty())
err_msg += "; " + res->body;
std::string err_msg = "Configure failed " + key;
if (res) {
err_msg += "; HTTP" + std::to_string(res->status);
if (!res->body.empty())
err_msg += "; " + res->body;
}
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, err_msg);
}
}