Use ctx in getButtonDisabled function

Instead of using exceptions utilize API with the context pointer inside
the getButtonDisabled function.

Change-Id: Ib5515f17ba066c00bc8e0a0245ffa57efd25e72b
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
diff --git a/chassishandler.cpp b/chassishandler.cpp
index de06c85..10414b1 100644
--- a/chassishandler.cpp
+++ b/chassishandler.cpp
@@ -1037,22 +1037,26 @@
 }
 } // namespace power_policy
 
-static std::optional<bool> getButtonDisabled(const std::string& buttonPath,
-                                             const std::string& buttonIntf)
+static std::optional<bool>
+    getButtonDisabled(ipmi::Context::ptr& ctx, const std::string& buttonPath,
+                      const std::string& buttonIntf)
 {
-    std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
     bool buttonDisabled = false;
-    try
+    boost::system::error_code ec;
+    std::string service;
+    ec = ipmi::getService(ctx, buttonIntf, buttonPath, service);
+    if (!ec)
     {
-        auto service = ipmi::getService(*busp, buttonIntf, buttonPath);
-        ipmi::Value enabled = ipmi::getDbusProperty(*busp, service, buttonPath,
-                                                    buttonIntf, "Enabled");
-        buttonDisabled = !std::get<bool>(enabled);
+        bool enabled;
+        ec = ipmi::getDbusProperty(ctx, service, buttonPath, buttonIntf,
+                                   "Enabled", enabled);
+        buttonDisabled = !enabled;
     }
-    catch (const sdbusplus::exception_t& e)
+
+    if (ec)
     {
         lg2::error("Fail to get button Enabled property ({PATH}): {ERROR}",
-                   "PATH", buttonPath, "ERROR", e);
+                   "PATH", buttonPath, "ERROR", ec.message());
         return std::nullopt;
     }
     return std::make_optional(buttonDisabled);
@@ -1183,7 +1187,7 @@
 
     //  Front Panel Button Capabilities and disable/enable status(Optional)
     std::optional<bool> powerButtonReading =
-        getButtonDisabled(powerButtonPath, powerButtonIntf);
+        getButtonDisabled(ctx, powerButtonPath, powerButtonIntf);
     // allow disable if the interface is present
     bool powerButtonDisableAllow = static_cast<bool>(powerButtonReading);
     // default return the button is enabled (not disabled)
@@ -1195,7 +1199,7 @@
     }
 
     std::optional<bool> resetButtonReading =
-        getButtonDisabled(resetButtonPath, resetButtonIntf);
+        getButtonDisabled(ctx, resetButtonPath, resetButtonIntf);
     // allow disable if the interface is present
     bool resetButtonDisableAllow = static_cast<bool>(resetButtonReading);
     // default return the button is enabled (not disabled)