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: I85192219c1c34cf5fd6c6aca06a8b207d7e06697
diff --git a/app/watchdog_service.cpp b/app/watchdog_service.cpp
index 09b700f..e17f146 100644
--- a/app/watchdog_service.cpp
+++ b/app/watchdog_service.cpp
@@ -34,8 +34,11 @@
     bool wasValid = wd_service.isValid(bus);
     auto request = wd_service.newMethodCall(bus, wd_intf, "ResetTimeRemaining");
     request.append(enableWatchdog);
-    auto response = bus.call(request);
-    if (response.is_method_error())
+    try
+    {
+        auto response = bus.call(request);
+    }
+    catch (const std::exception& e)
     {
         wd_service.invalidate();
         if (wasValid)
@@ -45,7 +48,8 @@
         }
         log<level::ERR>(
             "WatchdogService: Method error resetting time remaining",
-            entry("ENABLE_WATCHDOG=%d", !!enableWatchdog));
+            entry("ENABLE_WATCHDOG=%d", !!enableWatchdog),
+            entry("ERROR=%s", e.what()));
         elog<InternalFailure>();
     }
 }
@@ -55,8 +59,14 @@
     bool wasValid = wd_service.isValid(bus);
     auto request = wd_service.newMethodCall(bus, prop_intf, "GetAll");
     request.append(wd_intf);
-    auto response = bus.call(request);
-    if (response.is_method_error())
+
+    std::map<std::string, std::variant<bool, uint64_t, std::string>> properties;
+    try
+    {
+        auto response = bus.call(request);
+        response.read(properties);
+    }
+    catch (const std::exception& e)
     {
         wd_service.invalidate();
         if (wasValid)
@@ -64,14 +74,13 @@
             // Retry the request once in case the cached service was stale
             return getProperties();
         }
-        log<level::ERR>("WatchdogService: Method error getting properties");
+        log<level::ERR>("WatchdogService: Method error getting properties",
+                        entry("ERROR=%s", e.what()));
         elog<InternalFailure>();
     }
+
     try
     {
-        std::map<std::string, std::variant<bool, uint64_t, std::string>>
-            properties;
-        response.read(properties);
         Properties wd_prop;
         wd_prop.initialized = std::get<bool>(properties.at("Initialized"));
         wd_prop.enabled = std::get<bool>(properties.at("Enabled"));
@@ -90,8 +99,7 @@
     catch (const std::exception& e)
     {
         log<level::ERR>("WatchdogService: Decode error in get properties",
-                        entry("ERROR=%s", e.what()),
-                        entry("REPLY_SIG=%s", response.get_signature()));
+                        entry("ERROR=%s", e.what()));
         elog<InternalFailure>();
     }
 
@@ -107,8 +115,14 @@
     bool wasValid = wd_service.isValid(bus);
     auto request = wd_service.newMethodCall(bus, prop_intf, "Get");
     request.append(wd_intf, key);
-    auto response = bus.call(request);
-    if (response.is_method_error())
+    try
+    {
+        auto response = bus.call(request);
+        std::variant<T> value;
+        response.read(value);
+        return std::get<T>(value);
+    }
+    catch (const std::exception& e)
     {
         wd_service.invalidate();
         if (wasValid)
@@ -117,21 +131,8 @@
             return getProperty<T>(key);
         }
         log<level::ERR>("WatchdogService: Method error getting property",
-                        entry("PROPERTY=%s", key.c_str()));
-        elog<InternalFailure>();
-    }
-    try
-    {
-        std::variant<T> value;
-        response.read(value);
-        return std::get<T>(value);
-    }
-    catch (const std::exception& e)
-    {
-        log<level::ERR>("WatchdogService: Decode error in get property",
                         entry("PROPERTY=%s", key.c_str()),
-                        entry("ERROR=%s", e.what()),
-                        entry("REPLY_SIG=%s", response.get_signature()));
+                        entry("ERROR=%s", e.what()));
         elog<InternalFailure>();
     }
 
@@ -147,8 +148,11 @@
     bool wasValid = wd_service.isValid(bus);
     auto request = wd_service.newMethodCall(bus, prop_intf, "Set");
     request.append(wd_intf, key, std::variant<T>(val));
-    auto response = bus.call(request);
-    if (response.is_method_error())
+    try
+    {
+        auto response = bus.call(request);
+    }
+    catch (const std::exception& e)
     {
         wd_service.invalidate();
         if (wasValid)
@@ -158,7 +162,8 @@
             return;
         }
         log<level::ERR>("WatchdogService: Method error setting property",
-                        entry("PROPERTY=%s", key.c_str()));
+                        entry("PROPERTY=%s", key.c_str()),
+                        entry("ERROR=%s", e.what()));
         elog<InternalFailure>();
     }
 }