Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-du-car committed Apr 17, 2024
1 parent 720e4d7 commit 01a48eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#pragma once
#include <tmx/TmxException.hpp>

namespace RSUHealthMonitor
{
class RSUConfigurationException : public tmx::TmxException
class RSUConfigurationException : public std::runtime_error
{
public:
using TmxException::TmxException;
RSUConfigurationException(const std::string &msg) : std::runtime_error(msg){};
};
}
20 changes: 13 additions & 7 deletions src/v2i-hub/RSUHealthMonitorPlugin/src/RSUConfigurationList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace RSUHealthMonitor
auto rsuArray = json[RSUSKey];
if (!rsuArray.isArray())
{
throw RSUConfigurationException("RSUS is not an array.");
throw RSUConfigurationException("RSUConfigurationList: Missing RSUS array.");
}
for (auto i = 0; i != rsuArray.size(); i++)
{
Expand All @@ -37,17 +37,20 @@ namespace RSUHealthMonitor
}
else
{
throw RSUConfigurationException("RSU IP does not exist.");
std::string errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: RSU IP [" + std::string(RSUIpKey) + "] is required.";
throw RSUConfigurationException(errMsg);
}

if (rsuArray[i].isMember(SNMPPortKey))
{
auto port = static_cast<uint16_t>(atoi(rsuArray[i][SNMPPortKey].asCString()));
port != 0 ? config.snmpPort = port : throw RSUConfigurationException("Invalid port number in string format.");
std::string errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: Invalid SNMP port number in string format.";
port != 0 ? config.snmpPort = port : throw RSUConfigurationException(errMsg);
}
else
{
throw RSUConfigurationException("Either SNMP port does not exist.");
std::string errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: SNMP port [" + std::string(SNMPPortKey) + "] is required.";
throw RSUConfigurationException(errMsg);
}

if (rsuArray[i].isMember(AuthPassPhraseKey))
Expand All @@ -56,7 +59,8 @@ namespace RSUHealthMonitor
}
else
{
throw RSUConfigurationException("Authentication pass phrase does not exist.");
std::string errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: Authentication pass phrase [" + std::string(AuthPassPhraseKey) + "] is required.";
throw RSUConfigurationException(errMsg);
}

if (rsuArray[i].isMember(UserKey))
Expand All @@ -65,7 +69,8 @@ namespace RSUHealthMonitor
}
else
{
throw RSUConfigurationException("User does not exist.");
std::string errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: User [" + std::string(UserKey) + "] is required.";
throw RSUConfigurationException(errMsg);
}

if (rsuArray[i].isMember(RSUMIBVersionKey))
Expand All @@ -75,7 +80,8 @@ namespace RSUHealthMonitor
}
else
{
throw RSUConfigurationException("RSU mib version does not exist.");
std::string errMsg = "RSUConfigurationList [" + std::to_string(i + 1) + "]: RSU MIB version [" + std::string(RSUMIBVersionKey) + "] is required.";
throw RSUConfigurationException(errMsg);
}
tempConfigs.push_back(config);
}
Expand Down

0 comments on commit 01a48eb

Please sign in to comment.