Remove is_method_error method
Remove the usage of is_method_error()[1], and add try-catch to handle
D-Bus exceptions around mapper call.
[1]https://github.com/openbmc/sdbusplus/commit/079fb85a398d90800935e3985bb1266a7530a26e#diff-945669e8bd9cab4ecc83a574a732921281b2c79eb8bba65efff11736ad18f92bR237-R240
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I8bbd5396e69dfa343936a9275c8d6ff2cf76c8a9
diff --git a/presence/gpio_presence.cpp b/presence/gpio_presence.cpp
index c6e26b5..35326a9 100644
--- a/presence/gpio_presence.cpp
+++ b/presence/gpio_presence.cpp
@@ -37,23 +37,18 @@
mapperCall.append(path);
mapperCall.append(std::vector<std::string>({interface}));
- auto mapperResponseMsg = bus.call(mapperCall);
- if (mapperResponseMsg.is_method_error())
+ std::map<std::string, std::vector<std::string>> mapperResponse;
+ try
+ {
+ auto mapperResponseMsg = bus.call(mapperCall);
+ mapperResponseMsg.read(mapperResponse);
+ }
+ catch (const sdbusplus::exception_t& e)
{
log<level::ERR>("Error in mapper call to get service name",
entry("PATH=%s", path.c_str()),
- entry("INTERFACE=%s", interface.c_str()));
- elog<InternalFailure>();
- }
-
- std::map<std::string, std::vector<std::string>> mapperResponse;
- mapperResponseMsg.read(mapperResponse);
-
- if (mapperResponse.empty())
- {
- log<level::ERR>("Error in mapper response for getting service name",
- entry("PATH=%s", path.c_str()),
- entry("INTERFACE=%s", interface.c_str()));
+ entry("INTERFACE=%s", interface.c_str()),
+ entry("ERROR=%s", e.what()));
elog<InternalFailure>();
}
@@ -174,10 +169,14 @@
auto invMsg = bus.new_method_call(invService.c_str(), INVENTORY_PATH,
INVENTORY_INTF, "Notify");
invMsg.append(std::move(invObj));
- auto invMgrResponseMsg = bus.call(invMsg);
- if (invMgrResponseMsg.is_method_error())
+ try
{
- log<level::ERR>("Error in inventory manager call to update inventory");
+ auto invMgrResponseMsg = bus.call(invMsg);
+ }
+ catch (const sdbusplus::exception_t& e)
+ {
+ log<level::ERR>("Error in inventory manager call to update inventory",
+ entry("ERROR=%s", e.what()));
elog<InternalFailure>();
}
}