summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2018-12-06 22:53:53 +0300
committerEd Tanous <ed.tanous@intel.com>2018-12-14 00:55:40 +0300
commitdc2f9f11e726c02667e1c35080b15b20a4e62b33 (patch)
tree66e2f9cb12acc71b188d50f9038f6f7a0a39a44d
parent2ae600964780d469058a336eb38e9cfa30d41351 (diff)
downloadbmcweb-dc2f9f11e726c02667e1c35080b15b20a4e62b33.tar.xz
REST: For GET, return errors in JSON
For the failure cases, return the error messages in JSON, the same as the python REST server does. Change-Id: I150fec3ade738d1bd5425a3ea7cceb6c5539f9f6 Signed-off-by: Matt Spinler <spinler@us.ibm.com>
-rw-r--r--include/openbmc_dbus_rest.hpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 735db07367..0ab3908473 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -37,6 +37,7 @@ using GetSubTreeType = std::vector<
const std::string notFoundMsg = "404 Not Found";
const std::string notFoundDesc =
"org.freedesktop.DBus.Error.FileNotFound: path or object not found";
+const std::string propNotFoundDesc = "The specified property cannot be found";
void setErrorResponse(crow::Response &res, boost::beast::http::status result,
const std::string &desc, const std::string &msg)
@@ -999,7 +1000,8 @@ void handleGet(crow::Response &res, std::string &objectPath,
const GetObjectType &object_names) {
if (ec || object_names.size() <= 0)
{
- res.result(boost::beast::http::status::not_found);
+ setErrorResponse(res, boost::beast::http::status::not_found,
+ notFoundDesc, notFoundMsg);
res.end();
return;
}
@@ -1015,7 +1017,8 @@ void handleGet(crow::Response &res, std::string &objectPath,
if (interfaceNames.size() <= 0)
{
- res.result(boost::beast::http::status::not_found);
+ setErrorResponse(res, boost::beast::http::status::not_found,
+ notFoundDesc, notFoundMsg);
res.end();
return;
}
@@ -1064,10 +1067,19 @@ void handleGet(crow::Response &res, std::string &objectPath,
}
if (response.use_count() == 1)
{
- res.jsonValue = {{"status", "ok"},
- {"message", "200 OK"},
- {"data", *response}};
-
+ if (!propertyName->empty() && response->empty())
+ {
+ setErrorResponse(
+ res,
+ boost::beast::http::status::not_found,
+ propNotFoundDesc, notFoundMsg);
+ }
+ else
+ {
+ res.jsonValue = {{"status", "ok"},
+ {"message", "200 OK"},
+ {"data", *response}};
+ }
res.end();
}
},