Handle D-Bus exceptions
The is_method_error method is deprecated, remove and add try-catch
to handler D-Bus exceptions around mapper call.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I1a40b6550b51059e13a71676f5daeb3f637f9182
diff --git a/functor.cpp b/functor.cpp
index b8771d7..d0dbbcc 100644
--- a/functor.cpp
+++ b/functor.cpp
@@ -19,6 +19,7 @@
#include "manager.hpp"
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
namespace phosphor
@@ -56,15 +57,19 @@
mapperCall.append(path);
mapperCall.append(std::vector<std::string>({_iface}));
- 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 std::exception& e)
+ {
+ lg2::error("Failed to execute GetObject method: {ERROR}", "ERROR",
+ e);
return false;
}
- std::map<std::string, std::vector<std::string>> mapperResponse;
- mapperResponseMsg.read(mapperResponse);
-
if (mapperResponse.empty())
{
return false;
@@ -95,13 +100,16 @@
hostCall.append(_iface);
hostCall.append(_property);
- auto hostResponseMsg = bus.call(hostCall);
- if (hostResponseMsg.is_method_error())
+ try
{
+ auto hostResponseMsg = bus.call(hostCall);
+ return eval(hostResponseMsg);
+ }
+ catch (const std::exception& e)
+ {
+ lg2::error("Failed to execute Get method: {ERROR}", "ERROR", e);
return false;
}
-
- return eval(hostResponseMsg);
}
} // namespace functor