REST: method call: return D-Bus error desc
When invoking a D-Bus method call via the 'action' URL, return
the error that came back from the D-Bus call as opposed to just
hardcoding one.
Tested: A POST on /xyz/openbmc_project/dump/action/CreateDump when
no more dumps can be created now returns:
{
"data": {
"description": "xyz.openbmc_project.Dump.Create.Error.QuotaExceeded"
},
"message": "Dump not captured due to a cap.",
"status": "error"
}
Change-Id: Ifd0c97f82ff05842fa0f36ef3bb1aaba42ad7d49
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index cfbe4cb..0aa23e2 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -415,13 +415,7 @@
{
if (!methodPassed)
{
- if (methodFailed)
- {
- setErrorResponse(res,
- boost::beast::http::status::bad_request,
- "Method call failed", methodFailedMsg);
- }
- else
+ if (!methodFailed)
{
setErrorResponse(res, boost::beast::http::status::not_found,
methodNotFoundDesc, notFoundMsg);
@@ -1388,6 +1382,25 @@
if (ec)
{
transaction->methodFailed = true;
+ const sd_bus_error *e = m.get_error();
+
+ if (e)
+ {
+ setErrorResponse(
+ transaction->res,
+ boost::beast::http::status::
+ bad_request,
+ e->name, e->message);
+ }
+ else
+ {
+ setErrorResponse(
+ transaction->res,
+ boost::beast::http::status::
+ bad_request,
+ "Method call failed",
+ methodFailedMsg);
+ }
return;
}
else
@@ -1873,8 +1886,11 @@
boost::beast::http::
status::
forbidden,
- e->name,
- e->message);
+ (e) ? e->name
+ : ec.category()
+ .name(),
+ (e) ? e->message
+ : ec.message());
}
else
{