Fix Power Restore Policy not valid enum error
When the client passes a value that is not in list of accepted values
use propertyValueNotInList.
Tested:
curl -k -X PATCH -d '{"PowerRestorePolicy":"badvalue"}'\
https://${bmc}/redfish/v1/Systems/system
{
"PowerRestorePolicy@Message.ExtendedInfo": [
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The value badvalue for the property PowerRestorePolicy is not in the list of acceptable values.",
"MessageArgs": [
"badvalue",
"PowerRestorePolicy"
],
"MessageId": "Base.1.8.1.PropertyValueNotInList",
Change-Id: Icfa910c9f79aa6ff0a87f748b55ad52d8ad411d8
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 57f6b96..91da523 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -1543,7 +1543,7 @@
* @return None.
*/
inline void setPowerRestorePolicy(const std::shared_ptr<AsyncResp>& aResp,
- std::optional<std::string> policy)
+ const std::string& policy)
{
BMCWEB_LOG_DEBUG << "Set power restore policy.";
@@ -1557,10 +1557,11 @@
std::string powerRestorPolicy;
- auto policyMapsIt = policyMaps.find(*policy);
+ auto policyMapsIt = policyMaps.find(policy);
if (policyMapsIt == policyMaps.end())
{
- messages::internalError(aResp->res);
+ messages::propertyValueNotInList(aResp->res, policy,
+ "PowerRestorePolicy");
return;
}
@@ -2252,7 +2253,7 @@
if (powerRestorePolicy)
{
- setPowerRestorePolicy(asyncResp, std::move(*powerRestorePolicy));
+ setPowerRestorePolicy(asyncResp, *powerRestorePolicy);
}
}
};