REST: For enumerate, return the error in JSON
The only way enumerate can fail is if the GetSubTree call fails,
and that will only happen if the path isn't a valid D-Bus object.
In that case, return the standard REST error JSON response for
org.freedesktop.DBus.Error.FileNotFound.
Change-Id: Ie68761c3ee67aa337761567b8a76bd9c9ebddc19
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 2e338bb..735db07 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -34,6 +34,19 @@
std::pair<std::string,
std::vector<std::pair<std::string, std::vector<std::string>>>>>;
+const std::string notFoundMsg = "404 Not Found";
+const std::string notFoundDesc =
+ "org.freedesktop.DBus.Error.FileNotFound: path or object not found";
+
+void setErrorResponse(crow::Response &res, boost::beast::http::status result,
+ const std::string &desc, const std::string &msg)
+{
+ res.result(result);
+ res.jsonValue = {{"data", {{"description", desc}}},
+ {"message", msg},
+ {"status", "error"}};
+}
+
void introspectObjects(const std::string &processName,
const std::string &objectPath,
std::shared_ptr<bmcweb::AsyncResp> transaction)
@@ -951,6 +964,11 @@
if (ec)
{
+ BMCWEB_LOG_ERROR << "GetSubTree failed on "
+ << transaction->objectPath;
+ setErrorResponse(transaction->asyncResp->res,
+ boost::beast::http::status::not_found,
+ notFoundDesc, notFoundMsg);
return;
}