Reimplement presistent data loading in no-throw way

Reimplemented persistent data file loading in no-throw approach
to avoid errors during startup when bmcweb_persistent_data.json
has been corrupted. Additionally this will allow to turn off all
exceptions in the project (removed try-catch).

Change-Id: I9bf863ebfd7ce9125d1e7e948f7ac739db94e009
Signed-off-by: Kowalski, Kamil <kamil.kowalski@intel.com>
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
diff --git a/include/persistent_data_middleware.hpp b/include/persistent_data_middleware.hpp
index 9d6195c..fcab52f 100644
--- a/include/persistent_data_middleware.hpp
+++ b/include/persistent_data_middleware.hpp
@@ -47,10 +47,36 @@
       // call with exceptions disabled
       auto data = nlohmann::json::parse(persistent_file, nullptr, false);
       if (!data.is_discarded()) {
-        file_revision = data.value("revision", 0);
-        PersistentData::session_store->auth_tokens =
-            data.value("sessions", decltype(session_store->auth_tokens)());
-        system_uuid = data.value("system_uuid", "");
+        auto jRevision = data.find("revision");
+        auto jUuid = data.find("system_uuid");
+        auto jSessions = data.find("sessions");
+
+        file_revision = 0;
+        if (jRevision != data.end()) {
+          if (jRevision->is_number_integer()) {
+            file_revision = jRevision->get<int>();
+          }
+        }
+
+        system_uuid = "";
+        if (jUuid != data.end()) {
+          if (jUuid->is_string()) {
+            system_uuid = jUuid->get<std::string>();
+          }
+        }
+
+        if (jSessions != data.end()) {
+          if (jSessions->is_object()) {
+            for (const auto& elem : *jSessions) {
+              UserSession newSession;
+
+              if (newSession.fromJson(elem)) {
+                session_store->auth_tokens.emplace(newSession.unique_id,
+                                                   std::move(newSession));
+              }
+            }
+          }
+        }
       }
     }
     bool need_write = false;