Move error messages to string_view
using std::string_view on these lets us call them in more contexts, and
allows us to inline some previously more complex code. In general, for
APIs like this, std::string_view should be preferred as it gives more
flexibility in calling conventions.
Tested:
curl --insecure "https://localhost:18080/redfish/v1/AccountService/Roles/foobar" ✔
{
"error": {
"@Message.ExtendedInfo": [
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The requested resource of type Role named 'foobar' was not found.",
"MessageArgs": [
"Role",
"foobar"
],
"MessageId": "Base.1.11.0.ResourceNotFound",
"MessageSeverity": "Critical",
"Resolution": "Provide a valid resource identifier and resubmit the request."
}
],
"code": "Base.1.11.0.ResourceNotFound",
"message": "The requested resource of type Role named 'foobar' was not found."
}
}
This is the same response as previously.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I8ee17120c42d2a13677648c3395aa4f9ec2bd51a
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index a5e8c23..acaa40a 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -682,8 +682,7 @@
if (config.empty())
{
BMCWEB_LOG_ERROR << "Empty Zones";
- messages::propertyValueFormatError(response->res,
- nlohmann::json::array(), "Zones");
+ messages::propertyValueFormatError(response->res, "[]", "Zones");
return false;
}
for (auto& odata : config)
@@ -1601,8 +1600,8 @@
if (createNewObject && it.value() == nullptr)
{
// can't delete a non-existent object
- messages::propertyValueNotInList(response->res, it.value(),
- name);
+ messages::propertyValueNotInList(response->res,
+ it.value().dump(), name);
continue;
}