Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIFI-13985: commands API will return 400 if command fails on device. #366

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/RESTAPI/RESTAPI_RPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace OpenWifi::RESTAPI_RPC {
Poco::JSON::Object RetObj;
Cmd.to_json(RetObj);
if (Handler != nullptr)
if (Cmd.ErrorCode){
return Handler->ReturnObject(RetObj, Poco::Net::HTTPResponse::HTTP_BAD_REQUEST);
}
return Handler->ReturnObject(RetObj);
return;
}
Expand Down Expand Up @@ -167,6 +170,15 @@ namespace OpenWifi::RESTAPI_RPC {
Cmd.AttachType = "";
}

// If the command fails on the device we should show it as failed and not return 200 OK
if (Cmd.ErrorCode) {
Logger.information(fmt::format(
"Command failed with error on device: {} Reason: {}.",
Cmd.ErrorCode, Cmd.ErrorText));
return SetCommandStatus(Cmd, Request, Response, Handler,
Storage::CommandExecutionType::COMMAND_FAILED, Logger);
}

if (Cmd.ErrorCode == 0 && Cmd.Command == uCentralProtocol::CONFIGURE) {
// we need to post a kafka event for this.
if (Params.has(uCentralProtocol::CONFIG) && Params.isObject(uCentralProtocol::CONFIG)) {
Expand All @@ -175,6 +187,7 @@ namespace OpenWifi::RESTAPI_RPC {
DeviceConfigurationChangeKafkaEvent KEvent(
Utils::SerialNumberToInt(Cmd.SerialNumber), Utils::Now(),
Config);

}
}

Expand Down
4 changes: 2 additions & 2 deletions src/framework/RESTAPI_Handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ namespace OpenWifi {

inline bool IsAuthorized(bool &Expired, bool &Contacted, bool SubOnly = false);

inline void ReturnObject(Poco::JSON::Object &Object) {
PrepareResponse();
inline void ReturnObject(Poco::JSON::Object &Object, Poco::Net::HTTPResponse::HTTPStatus Status = Poco::Net::HTTPResponse::HTTP_OK) {
PrepareResponse(Status);
if (Request != nullptr) {
// can we compress ???
auto AcceptedEncoding = Request->find("Accept-Encoding");
Expand Down
Loading