summaryrefslogtreecommitdiff
path: root/redfish-core/include
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-06-27 22:59:12 +0300
committerEd Tanous <ed@tanous.net>2023-06-13 20:48:37 +0300
commit2e8c4bda9c4b2809ca76bb227f818592515a3e4a (patch)
treec4c1532a1a5788c774d2b569136ffde66a6c9c72 /redfish-core/include
parente2616cc5d2093715bbbb5a7ff6aa0c86b2c466d4 (diff)
downloadbmcweb-2e8c4bda9c4b2809ca76bb227f818592515a3e4a.tar.xz
Make propertyValueTypeError more typesafe
Similar to the prior patchset in this series, propertyValueTypeError can be moved to safer constructs. This ensures that we are minimizing how many places we are calling dump() from, and allows us to reduce the amount of code written for error handling. Tested: PATCH /redfish/v1/SessionService {"SessionTimeout": "foo"} Returns PropertyValueTypeError in the same behavior as prior to this patch. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Iddff4b787f35c49bf923663d61bba156687f358c
Diffstat (limited to 'redfish-core/include')
-rw-r--r--redfish-core/include/error_messages.hpp4
-rw-r--r--redfish-core/include/utils/json_utils.hpp24
2 files changed, 6 insertions, 22 deletions
diff --git a/redfish-core/include/error_messages.hpp b/redfish-core/include/error_messages.hpp
index 99e9ae8f37..77aa8958f8 100644
--- a/redfish-core/include/error_messages.hpp
+++ b/redfish-core/include/error_messages.hpp
@@ -571,10 +571,10 @@ void operationTimeout(crow::Response& res);
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message PropertyValueTypeError formatted to JSON */
-nlohmann::json propertyValueTypeError(std::string_view arg1,
+nlohmann::json propertyValueTypeError(const nlohmann::json& arg1,
std::string_view arg2);
-void propertyValueTypeError(crow::Response& res, std::string_view arg1,
+void propertyValueTypeError(crow::Response& res, const nlohmann::json& arg1,
std::string_view arg2);
/**
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp
index 7c701428af..6e18157fc0 100644
--- a/redfish-core/include/utils/json_utils.hpp
+++ b/redfish-core/include/utils/json_utils.hpp
@@ -219,20 +219,12 @@ bool unpackValue(nlohmann::json& jsonValue, std::string_view key,
{
if (!jsonValue.is_array())
{
- messages::propertyValueTypeError(
- res,
- res.jsonValue.dump(2, ' ', true,
- nlohmann::json::error_handler_t::replace),
- key);
+ messages::propertyValueTypeError(res, res.jsonValue, key);
return false;
}
if (jsonValue.size() != value.size())
{
- messages::propertyValueTypeError(
- res,
- res.jsonValue.dump(2, ' ', true,
- nlohmann::json::error_handler_t::replace),
- key);
+ messages::propertyValueTypeError(res, res.jsonValue, key);
return false;
}
size_t index = 0;
@@ -247,11 +239,7 @@ bool unpackValue(nlohmann::json& jsonValue, std::string_view key,
{
if (!jsonValue.is_array())
{
- messages::propertyValueTypeError(
- res,
- res.jsonValue.dump(2, ' ', true,
- nlohmann::json::error_handler_t::replace),
- key);
+ messages::propertyValueTypeError(res, res.jsonValue, key);
return false;
}
@@ -270,11 +258,7 @@ bool unpackValue(nlohmann::json& jsonValue, std::string_view key,
{
if (ec == UnpackErrorCode::invalidType)
{
- messages::propertyValueTypeError(
- res,
- jsonValue.dump(2, ' ', true,
- nlohmann::json::error_handler_t::replace),
- key);
+ messages::propertyValueTypeError(res, jsonValue, key);
}
else if (ec == UnpackErrorCode::outOfRange)
{