Skip to content

Commit

Permalink
fix: fix crash for non-configure commands
Browse files Browse the repository at this point in the history
https://telecominfraproject.atlassian.net/browse/WIFI-14027

Summary of changes:
- Modified code to relay errors only in case of configure command and
  strict mode.

Signed-off-by: Ivan Chvets <[email protected]>
  • Loading branch information
i-chvets committed Aug 1, 2024
1 parent 451680c commit cf6864c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/RESTAPI/RESTAPI_RPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ namespace OpenWifi::RESTAPI_RPC {
if (StorageService()->AddCommand(Cmd.SerialNumber, Cmd, Status)) {
Poco::JSON::Object RetObj;
Cmd.to_json(RetObj);
if (Handler != nullptr)
if (Handler->GetBoolParameter("strict", false) && Cmd.ErrorCode){
return Handler->ReturnObject(RetObj, Poco::Net::HTTPResponse::HTTP_BAD_REQUEST);
if (Handler == nullptr) {
// nothing to process/return
return;
}
Poco::Net::HTTPResponse::HTTPStatus cmd_status = Poco::Net::HTTPResponse::HTTP_OK;
if (Cmd.ErrorCode > 0) {
// command returned error
if (Handler->GetBoolParameter("strict", false) && Cmd.Command != uCentralProtocol::CONFIGURE) {
// in strict validation mode and commands other than configure
// setup command failure status
cmd_status = Poco::Net::HTTPResponse::HTTP_BAD_REQUEST;;
}
return Handler->ReturnObject(RetObj);
return;
}
return Handler->ReturnObject(RetObj, cmd_status);
}
if (Handler != nullptr)
return Handler->ReturnStatus(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
Expand Down Expand Up @@ -171,7 +179,9 @@ namespace OpenWifi::RESTAPI_RPC {
}

// If the command fails on the device we should show it as failed and not return 200 OK
if (Handler->GetBoolParameter("strict", false) && Cmd.ErrorCode) {
if (Cmd.ErrorCode && Handler->GetBoolParameter("strict", false) && Cmd.Command != uCentralProtocol::CONFIGURE) {
// in strict validation mode and commands other than configure
// return failed status
Logger.information(fmt::format(
"Command failed with error on device: {} Reason: {}.",
Cmd.ErrorCode, Cmd.ErrorText));
Expand Down

0 comments on commit cf6864c

Please sign in to comment.