Move getErrCodeMsg API to common_utility
This commit moves the getErrCodeMsg API from vpd_specific_utility to
common_utility file, to make it accessible to the other utility files.
Change-Id: Ib0aeeb2386ba2c55f2447d65a3be18b76eff46f3
Signed-off-by: Rekha Aparna <vrekhaaparna@ibm.com>
diff --git a/vpd-manager/include/utility/common_utility.hpp b/vpd-manager/include/utility/common_utility.hpp
index 9573aca..de7a9ae 100644
--- a/vpd-manager/include/utility/common_utility.hpp
+++ b/vpd-manager/include/utility/common_utility.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "constants.hpp"
+#include "error_codes.hpp"
#include "logger.hpp"
#include <algorithm>
@@ -37,6 +38,24 @@
namespace commonUtility
{
+/**
+ * @brief API to get error code message.
+ *
+ * @param[in] i_errCode - error code.
+ *
+ * @return Error message set for that error code. Otherwise empty
+ * string.
+ */
+inline std::string getErrCodeMsg(const uint16_t& i_errCode)
+{
+ if (errorCodeMap.find(i_errCode) != errorCodeMap.end())
+ {
+ return errorCodeMap.at(i_errCode);
+ }
+
+ return std::string{};
+}
+
/** @brief Return the hex representation of the incoming byte.
*
* @param [in] i_aByte - The input byte.