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/chassishandler.cpp b/chassishandler.cpp
index be0c4c1..89d3e00 100644
--- a/chassishandler.cpp
+++ b/chassishandler.cpp
@@ -1407,32 +1407,17 @@
 std::string getEnclosureIdentifyConnection()
 {
     // lookup enclosure_identify group owner(s) in mapper
-    auto mapperCall = chassis::internal::dbus.new_method_call(
-        ipmi::MAPPER_BUS_NAME, ipmi::MAPPER_OBJ, ipmi::MAPPER_INTF,
-        "GetObject");
-
-    mapperCall.append(identify_led_object_name);
-    static const std::vector<std::string> interfaces = {
-        "xyz.openbmc_project.Led.Group"};
-    mapperCall.append(interfaces);
-    auto mapperReply = chassis::internal::dbus.call(mapperCall);
-    if (mapperReply.is_method_error())
+    try
     {
-        log<level::ERR>("Chassis Identify: Error communicating to mapper.");
+        return ipmi::getService(*getSdBus(), "xyz.openbmc_project.Led.Group",
+                                identify_led_object_name);
+    }
+    catch (const std::exception& e)
+    {
+        log<level::ERR>("Chassis Identify: Error communicating to mapper.",
+                        entry("ERROR=%s", e.what()));
         elog<InternalFailure>();
     }
-    std::vector<std::pair<std::string, std::vector<std::string>>> mapperResp;
-    mapperReply.read(mapperResp);
-
-    if (mapperResp.size() != encIdentifyObjectsSize)
-    {
-        log<level::ERR>(
-            "Invalid number of enclosure identify objects.",
-            entry("ENC_IDENTITY_OBJECTS_SIZE=%d", mapperResp.size()));
-        elog<InternalFailure>();
-    }
-    auto pair = mapperResp[encIdentifyObjectsSize - 1];
-    return pair.first;
 }
 
 /** @brief Turn On/Off enclosure identify LED
@@ -1443,20 +1428,23 @@
 void enclosureIdentifyLed(bool flag)
 {
     using namespace chassis::internal;
-    std::string connection = getEnclosureIdentifyConnection();
-    auto msg = std::string("enclosureIdentifyLed(") +
-               boost::lexical_cast<std::string>(flag) + ")";
-    log<level::DEBUG>(msg.c_str());
-    auto led = dbus.new_method_call(connection.c_str(),
-                                    identify_led_object_name,
-                                    "org.freedesktop.DBus.Properties", "Set");
-    led.append("xyz.openbmc_project.Led.Group", "Asserted",
-               std::variant<bool>(flag));
-    auto ledReply = dbus.call(led);
-    if (ledReply.is_method_error())
+    try
+    {
+        std::string connection = getEnclosureIdentifyConnection();
+
+        auto msg = std::string("enclosureIdentifyLed(") +
+                   boost::lexical_cast<std::string>(flag) + ")";
+        log<level::DEBUG>(msg.c_str());
+
+        ipmi::setDbusProperty(*getSdBus(), connection, identify_led_object_name,
+                              "xyz.openbmc_project.Led.Group", "Asserted",
+                              flag);
+    }
+    catch (const std::exception& e)
     {
         log<level::ERR>("Chassis Identify: Error Setting State On/Off\n",
-                        entry("LED_STATE=%d", flag));
+                        entry("LED_STATE=%d", flag),
+                        entry("ERROR=%s", e.what()));
         elog<InternalFailure>();
     }
 }