Set error code for isFruReplaceableAtStandby API

This commit updates isFruReplaceableAtStandby API to set error code in
case of error. This helps caller of API to take action based on the
error code returned from the API.

Change-Id: I032ae984fefd9d1fc419c88a399db527f028f4fa
Signed-off-by: Rekha Aparna <vrekhaaparna@ibm.com>
diff --git a/vpd-manager/include/utility/json_utility.hpp b/vpd-manager/include/utility/json_utility.hpp
index 66be4fe..cf76a00 100644
--- a/vpd-manager/include/utility/json_utility.hpp
+++ b/vpd-manager/include/utility/json_utility.hpp
@@ -1051,35 +1051,30 @@
  *
  * @param[in] i_sysCfgJsonObj - System config JSON object.
  * @param[in] i_vpdFruPath - EEPROM path.
+ * @param[out] o_errCode - set error code in case of error.
  *
  * @return true if FRU is replaceable at standby. false otherwise.
  */
 inline bool isFruReplaceableAtStandby(const nlohmann::json& i_sysCfgJsonObj,
-                                      const std::string& i_vpdFruPath)
+                                      const std::string& i_vpdFruPath,
+                                      uint16_t& o_errCode)
 {
-    try
+    if (i_vpdFruPath.empty())
     {
-        if (i_vpdFruPath.empty())
-        {
-            throw std::runtime_error("Given FRU path is empty.");
-        }
-
-        if (i_sysCfgJsonObj.empty() || (!i_sysCfgJsonObj.contains("frus")))
-        {
-            throw std::runtime_error("Invalid system config JSON object.");
-        }
-
-        return ((i_sysCfgJsonObj["frus"][i_vpdFruPath].at(0))
-                    .contains("replaceableAtStandby") &&
-                (i_sysCfgJsonObj["frus"][i_vpdFruPath].at(
-                    0)["replaceableAtStandby"]));
+        o_errCode = error_code::INVALID_INPUT_PARAMETER;
+        return false;
     }
-    catch (const std::exception& l_error)
+
+    if (i_sysCfgJsonObj.empty() || (!i_sysCfgJsonObj.contains("frus")))
     {
-        // TODO: Log PEL
-        logging::logMessage(l_error.what());
+        o_errCode = error_code::INVALID_JSON;
     }
 
+    return (
+        (i_sysCfgJsonObj["frus"][i_vpdFruPath].at(0))
+            .contains("replaceableAtStandby") &&
+        (i_sysCfgJsonObj["frus"][i_vpdFruPath].at(0)["replaceableAtStandby"]));
+
     return false;
 }
 
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index a80957d..ca9df5a 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -1928,8 +1928,20 @@
         }
         else if (dbusUtility::isBMCReady())
         {
-            if (!jsonUtility::isFruReplaceableAtStandby(m_parsedJson,
-                                                        l_fruPath) &&
+            uint16_t l_errCode = 0;
+            bool isFruReplaceableAtStandby =
+                jsonUtility::isFruReplaceableAtStandby(m_parsedJson, l_fruPath,
+                                                       l_errCode);
+
+            if (l_errCode)
+            {
+                logging::logMessage(
+                    "Error while checking if FRU is replaceable at standby for FRU [" +
+                    std::string(i_dbusObjPath) + "], error : " +
+                    vpdSpecificUtility::getErrCodeMsg(l_errCode));
+            }
+
+            if (!isFruReplaceableAtStandby &&
                 (!jsonUtility::isFruReplaceableAtRuntime(m_parsedJson,
                                                          l_fruPath)))
             {