DectrisSimplonClient: Avoid dereferencing null pointers in error handling
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user