Set error code for getRedundantEepromPathFromJson

This commit updates getRedundantEepromPathFromJson  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: Iea1557048fd81e0174e07086731b6c5fe0eff233
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 852b501..d021f81 100644
--- a/vpd-manager/include/utility/json_utility.hpp
+++ b/vpd-manager/include/utility/json_utility.hpp
@@ -571,55 +571,50 @@
  *
  * @param[in] i_sysCfgJsonObj - System config JSON object.
  * @param[in] i_vpdPath - Path to where VPD is stored.
+ * @param[out] o_errCode - To set error code in case of error.
  *
  * @return On success return valid path, on failure return empty string.
  */
 inline std::string getRedundantEepromPathFromJson(
-    const nlohmann::json& i_sysCfgJsonObj,
-    const std::string& i_vpdPath) noexcept
+    const nlohmann::json& i_sysCfgJsonObj, const std::string& i_vpdPath,
+    uint16_t& o_errCode)
 {
-    try
+    if (i_vpdPath.empty())
     {
-        if (i_vpdPath.empty())
-        {
-            throw std::runtime_error("Path parameter is empty.");
-        }
-
-        if (!i_sysCfgJsonObj.contains("frus"))
-        {
-            throw std::runtime_error("Missing frus tag in system config JSON.");
-        }
-
-        // check if given path is FRU path
-        if (i_sysCfgJsonObj["frus"].contains(i_vpdPath))
-        {
-            return i_sysCfgJsonObj["frus"][i_vpdPath].at(0).value(
-                "redundantEeprom", "");
-        }
-
-        const nlohmann::json& l_fruList =
-            i_sysCfgJsonObj["frus"].get_ref<const nlohmann::json::object_t&>();
-
-        for (const auto& l_fru : l_fruList.items())
-        {
-            const std::string& l_fruPath = l_fru.key();
-            const std::string& l_redundantFruPath =
-                i_sysCfgJsonObj["frus"][l_fruPath].at(0).value(
-                    "redundantEeprom", "");
-
-            // check if given path is inventory path or redundant FRU path
-            if ((i_sysCfgJsonObj["frus"][l_fruPath].at(0).value(
-                     "inventoryPath", "") == i_vpdPath) ||
-                (l_redundantFruPath == i_vpdPath))
-            {
-                return l_redundantFruPath;
-            }
-        }
+        o_errCode = error_code::INVALID_INPUT_PARAMETER;
+        return std::string{};
     }
-    catch (const std::exception& l_ex)
+
+    if (!i_sysCfgJsonObj.contains("frus"))
     {
-        logging::logMessage("Failed to get redundant EEPROM path, error: " +
-                            std::string(l_ex.what()));
+        o_errCode = error_code::INVALID_JSON;
+        return std::string{};
+    }
+
+    // check if given path is FRU path
+    if (i_sysCfgJsonObj["frus"].contains(i_vpdPath))
+    {
+        return i_sysCfgJsonObj["frus"][i_vpdPath].at(0).value(
+            "redundantEeprom", "");
+    }
+
+    const nlohmann::json& l_fruList =
+        i_sysCfgJsonObj["frus"].get_ref<const nlohmann::json::object_t&>();
+
+    for (const auto& l_fru : l_fruList.items())
+    {
+        const std::string& l_fruPath = l_fru.key();
+        const std::string& l_redundantFruPath =
+            i_sysCfgJsonObj["frus"][l_fruPath].at(0).value("redundantEeprom",
+                                                           "");
+
+        // check if given path is inventory path or redundant FRU path
+        if ((i_sysCfgJsonObj["frus"][l_fruPath].at(0).value("inventoryPath",
+                                                            "") == i_vpdPath) ||
+            (l_redundantFruPath == i_vpdPath))
+        {
+            return l_redundantFruPath;
+        }
     }
 
     return std::string();
@@ -872,8 +867,19 @@
 
                 // Get redundant hardware path if present in system config JSON
                 l_redundantFruPath =
-                    jsonUtility::getRedundantEepromPathFromJson(i_sysCfgJsonObj,
-                                                                l_fruPath);
+                    jsonUtility::getRedundantEepromPathFromJson(
+                        i_sysCfgJsonObj, l_fruPath, l_errCode);
+
+                if (l_errCode)
+                {
+                    logging::logMessage(
+                        "Failed to get redundant EEPROM path for FRU [" +
+                        l_fruPath + "], error : " +
+                        vpdSpecificUtility::getErrCodeMsg(l_errCode));
+
+                    return std::make_tuple(io_vpdPath, l_inventoryObjPath,
+                                           l_redundantFruPath);
+                }
             }
 
             logging::logMessage(