show message if there is no error message set

This commit is contained in:
proddy
2024-07-23 20:48:06 +02:00
parent e30c2b673e
commit 76418dd39d

View File

@@ -343,16 +343,20 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char *
// see if there is a command registered and it's valid // see if there is a command registered and it's valid
auto cf = find_command(device_type, device_id, cmd, flag); auto cf = find_command(device_type, device_id, cmd, flag);
if (!cf) { if (!cf) {
std::string err = std::string("unknown command ") + cmd; // if we don't already have a message set, set it to invalid command
LOG_WARNING("Command failed: %s", err.c_str()); if (output["message"]) {
LOG_WARNING("Command failed: %s", output["message"].as<const char *>());
// if we don't alread have a message set, set it to invalid command } else {
if (!output["message"]) { std::string err = "no command " + std::string(cmd) + " in " + dname;
output["message"] = err; output["message"] = err;
LOG_WARNING("Command failed: %s", err.c_str());
} }
return CommandRet::ERROR; return CommandRet::ERROR;
} }
// TODO here
output.clear(); // we have a command function, clear messages from device_value_info
// before calling the command, check permissions and abort if not authorized // before calling the command, check permissions and abort if not authorized
if (cf->has_flags(CommandFlag::ADMIN_ONLY) && !is_admin) { if (cf->has_flags(CommandFlag::ADMIN_ONLY) && !is_admin) {
LOG_WARNING("Command failed: authentication failed"); LOG_WARNING("Command failed: authentication failed");