summaryrefslogtreecommitdiff
path: root/include/openbmc_dbus_rest.hpp
diff options
context:
space:
mode:
authorTim Lee <timlee660101@gmail.com>2021-05-25 03:59:19 +0300
committerTim Lee <timlee660101@gmail.com>2021-05-25 05:06:23 +0300
commitb623d9c1b6605978eb6158619bb43c79a9f543fd (patch)
treeab0e84ceef06a2567662eb2f760beacd625f903f /include/openbmc_dbus_rest.hpp
parent2ebb9683287cf6b1a2f2cc3c077bd99aceefa8dd (diff)
downloadbmcweb-b623d9c1b6605978eb6158619bb43c79a9f543fd.tar.xz
dbus_rest: return error response with not found when bad dbus request
Symptom: Run automation test "Create Two User Initiated Dump And Delete One" then we got ERROR as below. Create Two User Initiated Dump And Delete One | FAIL | Test Bmc Dump :: Test dump functionality of OpenBMC. | FAIL | **ERROR** 200 != 404 Root cause: handleGet() function of dbus_rest in bmcweb should be return setErrorResponse() when doing get request after delete 1 bmc dump. After checking code flow that will print "message 200 OK", not "message 404 Not Found". Due to /xyz/openbmc_project/dump/bmc/entry/1 object path already be deleted and not exist. Thus when doing get request again with the deleted object path, we will found that async_send() call return "Bad dbus request error". But, code flow will keep to response with [200], not [404]. Response should be [404] not [200]. That's why auto test report "**ERROR** 200 != 404". Solution: Add setErrorResponse with not found error message return when async_send return "Bad dbus request error". Tested: robot -t Create_Two_User_Initiated_Dump_And_Delete_One redfish/extended/test_bmc_dump.robot Create Two User Initiated Dump And Delete One | PASS | Test Bmc Dump :: Test dump functionality of OpenBMC. | PASS | 1 critical test, 1 passed, 0 failed 1 test total, 1 passed, 0 failed Signed-off-by: Tim Lee <timlee660101@gmail.com> Change-Id: I81e4f22bc2a24f482a41b757835068ca81321437
Diffstat (limited to 'include/openbmc_dbus_rest.hpp')
-rw-r--r--include/openbmc_dbus_rest.hpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index b988095764..19c462f138 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -1698,34 +1698,34 @@ inline void handleGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
{
BMCWEB_LOG_ERROR << "Bad dbus request error: "
<< ec2;
+ setErrorResponse(
+ asyncResp->res,
+ boost::beast::http::status::not_found,
+ notFoundDesc, notFoundMsg);
+ return;
+ }
+ nlohmann::json properties;
+ int r = convertDBusToJSON("a{sv}", msg, properties);
+ if (r < 0)
+ {
+ BMCWEB_LOG_ERROR << "convertDBusToJSON failed";
}
else
{
- nlohmann::json properties;
- int r =
- convertDBusToJSON("a{sv}", msg, properties);
- if (r < 0)
+ for (auto& prop : properties.items())
{
- BMCWEB_LOG_ERROR
- << "convertDBusToJSON failed";
- }
- else
- {
- for (auto& prop : properties.items())
- {
- // if property name is empty, or
- // matches our search query, add it
- // to the response json
+ // if property name is empty, or
+ // matches our search query, add it
+ // to the response json
- if (propertyName->empty())
- {
- (*response)[prop.key()] =
- std::move(prop.value());
- }
- else if (prop.key() == *propertyName)
- {
- *response = std::move(prop.value());
- }
+ if (propertyName->empty())
+ {
+ (*response)[prop.key()] =
+ std::move(prop.value());
+ }
+ else if (prop.key() == *propertyName)
+ {
+ *response = std::move(prop.value());
}
}
}