Remove deprecated is_method_error code

The is_method_error() function is no longer needed, instead a
try-catch block should be used instead.
Reference:
https://lists.ozlabs.org/pipermail/openbmc/2018-October/013696.html

Tested: Code update with field mode enabled, and ran Delete while
        host powered on, to check things still worked as expected.

Change-Id: I8ba8da32fe787c3151cc5be7cb9f55d1901e57cd
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/activation.cpp b/activation.cpp
index b9cd5ba..dd52fb6 100644
--- a/activation.cpp
+++ b/activation.cpp
@@ -106,21 +106,26 @@
 
     method.append(path);
     method.append(std::vector<std::string>({deleteInterface}));
-    auto mapperResponseMsg = bus.call(method);
-    if (mapperResponseMsg.is_method_error())
+
+    std::map<std::string, std::vector<std::string>> mapperResponse;
+
+    try
+    {
+        auto mapperResponseMsg = bus.call(method);
+        mapperResponseMsg.read(mapperResponse);
+        if (mapperResponse.begin() == mapperResponse.end())
+        {
+            log<level::ERR>("ERROR in reading the mapper response",
+                            entry("VERSIONPATH=%s", path.c_str()));
+            return;
+        }
+    }
+    catch (const SdBusError& e)
     {
         log<level::ERR>("Error in Get Delete Object",
                         entry("VERSIONPATH=%s", path.c_str()));
         return;
     }
-    std::map<std::string, std::vector<std::string>> mapperResponse;
-    mapperResponseMsg.read(mapperResponse);
-    if (mapperResponse.begin() == mapperResponse.end())
-    {
-        log<level::ERR>("ERROR in reading the mapper response",
-                        entry("VERSIONPATH=%s", path.c_str()));
-        return;
-    }
 
     // We need to find the phosphor-software-manager's version service
     // to invoke the delete interface
@@ -143,15 +148,7 @@
                                        deleteInterface, "Delete");
     try
     {
-        mapperResponseMsg = bus.call(method);
-
-        // Check that the bus call didn't result in an error
-        if (mapperResponseMsg.is_method_error())
-        {
-            log<level::ERR>("Error in Deleting image from image manager",
-                            entry("VERSIONPATH=%s", path.c_str()));
-            return;
-        }
+        bus.call(method);
     }
     catch (const SdBusError& e)
     {
@@ -216,16 +213,20 @@
                                       "org.freedesktop.DBus.Properties", "Get");
 
     method.append(FIELDMODE_INTERFACE, "FieldModeEnabled");
-    auto reply = bus.call(method);
-    if (reply.is_method_error())
+
+    sdbusplus::message::variant<bool> fieldMode;
+
+    try
+    {
+        auto reply = bus.call(method);
+        reply.read(fieldMode);
+        return sdbusplus::message::variant_ns::get<bool>(fieldMode);
+    }
+    catch (const SdBusError& e)
     {
         log<level::ERR>("Error in fieldModeEnabled getValue");
         elog<InternalFailure>();
     }
-    sdbusplus::message::variant<bool> fieldMode;
-    reply.read(fieldMode);
-
-    return sdbusplus::message::variant_ns::get<bool>(fieldMode);
 }
 
 #endif
diff --git a/item_updater.cpp b/item_updater.cpp
index f321b02..882acbb 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -214,38 +214,47 @@
 
     mapperCall.append(CHASSIS_STATE_PATH,
                       std::vector<std::string>({CHASSIS_STATE_OBJ}));
-    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);
+        if (mapperResponse.empty())
+        {
+            log<level::ERR>("Invalid Response from mapper");
+            elog<InternalFailure>();
+        }
+    }
+    catch (const sdbusplus::exception::SdBusError& e)
     {
         log<level::ERR>("Error in Mapper call");
         elog<InternalFailure>();
     }
-    using MapperResponseType = std::map<std::string, std::vector<std::string>>;
-    MapperResponseType mapperResponse;
-    mapperResponseMsg.read(mapperResponse);
-    if (mapperResponse.empty())
-    {
-        log<level::ERR>("Invalid Response from mapper");
-        elog<InternalFailure>();
-    }
 
     auto method = bus.new_method_call((mapperResponse.begin()->first).c_str(),
                                       CHASSIS_STATE_PATH,
                                       SYSTEMD_PROPERTY_INTERFACE, "Get");
     method.append(CHASSIS_STATE_OBJ, "CurrentPowerState");
-    auto response = bus.call(method);
-    if (response.is_method_error())
+
+    sdbusplus::message::variant<std::string> currentChassisState;
+
+    try
+    {
+        auto response = bus.call(method);
+        response.read(currentChassisState);
+        auto strParam = sdbusplus::message::variant_ns::get<std::string>(
+            currentChassisState);
+        return (strParam != CHASSIS_STATE_OFF);
+    }
+    catch (const sdbusplus::exception::SdBusError& e)
     {
         log<level::ERR>("Error in fetching current Chassis State",
                         entry("MAPPERRESPONSE=%s",
                               (mapperResponse.begin()->first).c_str()));
         elog<InternalFailure>();
     }
-    sdbusplus::message::variant<std::string> currentChassisState;
-    response.read(currentChassisState);
-    auto strParam =
-        sdbusplus::message::variant_ns::get<std::string>(currentChassisState);
-    return (strParam != CHASSIS_STATE_OFF);
 }
 
 } // namespace updater