Handle SdBusError exception in SEL commands

Change-Id: Ia79b3e2ea4ca8783c912c9864be32107d170d561
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/storagehandler.cpp b/storagehandler.cpp
index 72a0c08..871eae6 100644
--- a/storagehandler.cpp
+++ b/storagehandler.cpp
@@ -112,7 +112,18 @@
     responseData->eraseTimeStamp = ipmi::sel::invalidTimeStamp;
     responseData->operationSupport = ipmi::sel::operationSupport;
 
-    ipmi::sel::readLoggingObjectPaths(cache::paths);
+    try
+    {
+        ipmi::sel::readLoggingObjectPaths(cache::paths);
+    }
+    catch (const sdbusplus::exception::SdBusError& e)
+    {
+        // No action if reading log objects have failed for this command.
+        // readLoggingObjectPaths will throw exception if there are no log
+        // entries. The command will be responded with number of SEL entries
+        // as 0.
+    }
+
     responseData->entries = 0;
     responseData->addTimeStamp = ipmi::sel::invalidTimeStamp;
 
@@ -267,7 +278,17 @@
         return IPMI_CC_INVALID_RESERVATION_ID;
     }
 
-    ipmi::sel::readLoggingObjectPaths(cache::paths);
+    try
+    {
+        ipmi::sel::readLoggingObjectPaths(cache::paths);
+    }
+    catch (const sdbusplus::exception::SdBusError& e)
+    {
+        // readLoggingObjectPaths will throw exception if there are no error
+        // log entries.
+        *data_len = 0;
+        return IPMI_CC_SENSOR_INVALID;
+    }
 
     if (cache::paths.empty())
     {
@@ -371,6 +392,7 @@
     }
 
     sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
+    ipmi::sel::ObjectPaths objectPaths;
     auto depth = 0;
 
     auto mapperCall =
@@ -380,17 +402,25 @@
     mapperCall.append(depth);
     mapperCall.append(ipmi::sel::ObjectPaths({ipmi::sel::logEntryIntf}));
 
-    auto reply = bus.call(mapperCall);
-    if (reply.is_method_error())
+    try
     {
-        memcpy(response, &eraseProgress, sizeof(eraseProgress));
-        *data_len = sizeof(eraseProgress);
-        return IPMI_CC_OK;
-    }
+        auto reply = bus.call(mapperCall);
+        if (reply.is_method_error())
+        {
+            memcpy(response, &eraseProgress, sizeof(eraseProgress));
+            *data_len = sizeof(eraseProgress);
+            return IPMI_CC_OK;
+        }
 
-    ipmi::sel::ObjectPaths objectPaths;
-    reply.read(objectPaths);
-    if (objectPaths.empty())
+        reply.read(objectPaths);
+        if (objectPaths.empty())
+        {
+            memcpy(response, &eraseProgress, sizeof(eraseProgress));
+            *data_len = sizeof(eraseProgress);
+            return IPMI_CC_OK;
+        }
+    }
+    catch (const sdbusplus::exception::SdBusError& e)
     {
         memcpy(response, &eraseProgress, sizeof(eraseProgress));
         *data_len = sizeof(eraseProgress);