Collections should handle no members present
Upon booting a new system that doesn't have an inventory system working,
the mapper will return an error if no resources exist. This is
unfortunate, but an error we should handle properly. This commit
catches the "no paths found" return code from the mapper, and pushes
back an empty collection, instead of returning internal error (500).
Tested:
Resolved https://192.168.1.224:18080/redfish/v1/Chassis on a system with
no Chassis resources, and observed 200, and an empty collection
returned.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Iedaed198840e88fb0f3dc62423b064edff70972c
diff --git a/redfish-core/include/utils/collection.hpp b/redfish-core/include/utils/collection.hpp
index b6603b9..4511f61 100644
--- a/redfish-core/include/utils/collection.hpp
+++ b/redfish-core/include/utils/collection.hpp
@@ -33,9 +33,16 @@
[collectionPath,
aResp{std::move(aResp)}](const boost::system::error_code ec,
const std::vector<std::string>& objects) {
+ if (ec == boost::system::errc::io_error)
+ {
+ aResp->res.jsonValue["Members"] = nlohmann::json::array();
+ aResp->res.jsonValue["Members@odata.count"] = 0;
+ return;
+ }
+
if (ec)
{
- BMCWEB_LOG_DEBUG << "DBUS response error";
+ BMCWEB_LOG_DEBUG << "DBUS response error " << ec.value();
messages::internalError(aResp->res);
return;
}