log_services: Improve error handling for DBus Log Entry

Improve the error handling of the DBus Log Entry class:
1. Return internal error only if message, id, or severity are
   not initialized.
2. Handle Not Found error (404).
3. Escape the Entry ID used for the DBus call.

Tested:
A call to entries/foo returns not found:
$ curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Systems/system/LogServices/EventLog/Entries/foo
{
  "error": {
    "@Message.ExtendedInfo": [
      {
        "@odata.type": "#Message.v1_1_1.Message",
        "Message": "The requested resource of type EventLogEntry named foo was not found.",
        "MessageArgs": [
          "EventLogEntry",
          "foo"
        ],
        "MessageId": "Base.1.8.1.ResourceNotFound",
        "MessageSeverity": "Critical",
        "Resolution": "Provide a valid resource identifier and resubmit the request."
      }
    ],
    "code": "Base.1.8.1.ResourceNotFound",
    "message": "The requested resource of type EventLogEntry named foo was not found."
  }

Change-Id: Icac06b34c9d4bc570973da369eef42fd785b4bf7
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index f22744b..4975a37 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -1412,20 +1412,12 @@
                             if (propertyMap.first == "Id")
                             {
                                 id = std::get_if<uint32_t>(&propertyMap.second);
-                                if (id == nullptr)
-                                {
-                                    messages::internalError(asyncResp->res);
-                                }
                             }
                             else if (propertyMap.first == "Timestamp")
                             {
                                 const uint64_t* millisTimeStamp =
                                     std::get_if<uint64_t>(&propertyMap.second);
-                                if (millisTimeStamp == nullptr)
-                                {
-                                    messages::internalError(asyncResp->res);
-                                }
-                                else
+                                if (millisTimeStamp != nullptr)
                                 {
                                     timestamp = crow::utility::getTimestamp(
                                         *millisTimeStamp);
@@ -1435,11 +1427,7 @@
                             {
                                 const uint64_t* millisTimeStamp =
                                     std::get_if<uint64_t>(&propertyMap.second);
-                                if (millisTimeStamp == nullptr)
-                                {
-                                    messages::internalError(asyncResp->res);
-                                }
-                                else
+                                if (millisTimeStamp != nullptr)
                                 {
                                     updateTimestamp =
                                         crow::utility::getTimestamp(
@@ -1450,21 +1438,19 @@
                             {
                                 severity = std::get_if<std::string>(
                                     &propertyMap.second);
-                                if (severity == nullptr)
-                                {
-                                    messages::internalError(asyncResp->res);
-                                }
                             }
                             else if (propertyMap.first == "Message")
                             {
                                 message = std::get_if<std::string>(
                                     &propertyMap.second);
-                                if (message == nullptr)
-                                {
-                                    messages::internalError(asyncResp->res);
-                                }
                             }
                         }
+                        if (id == nullptr || message == nullptr ||
+                            severity == nullptr)
+                        {
+                            messages::internalError(asyncResp->res);
+                            return;
+                        }
                         thisEntry = {
                             {"@odata.type", "#LogEntry.v1_6_0.LogEntry"},
                             {"@odata.id",
@@ -1522,13 +1508,20 @@
             messages::internalError(asyncResp->res);
             return;
         }
-        const std::string& entryID = params[0];
+        std::string entryID = params[0];
+        dbus::utility::escapePathForDbus(entryID);
 
         // DBus implementation of EventLog/Entries
         // Make call to Logging Service to find all log entry objects
         crow::connections::systemBus->async_method_call(
             [asyncResp, entryID](const boost::system::error_code ec,
                                  GetManagedPropertyType& resp) {
+                if (ec.value() == EBADR)
+                {
+                    messages::resourceNotFound(asyncResp->res, "EventLogEntry",
+                                               entryID);
+                    return;
+                }
                 if (ec)
                 {
                     BMCWEB_LOG_ERROR
@@ -1547,20 +1540,12 @@
                     if (propertyMap.first == "Id")
                     {
                         id = std::get_if<uint32_t>(&propertyMap.second);
-                        if (id == nullptr)
-                        {
-                            messages::internalError(asyncResp->res);
-                        }
                     }
                     else if (propertyMap.first == "Timestamp")
                     {
                         const uint64_t* millisTimeStamp =
                             std::get_if<uint64_t>(&propertyMap.second);
-                        if (millisTimeStamp == nullptr)
-                        {
-                            messages::internalError(asyncResp->res);
-                        }
-                        else
+                        if (millisTimeStamp != nullptr)
                         {
                             timestamp =
                                 crow::utility::getTimestamp(*millisTimeStamp);
@@ -1570,11 +1555,7 @@
                     {
                         const uint64_t* millisTimeStamp =
                             std::get_if<uint64_t>(&propertyMap.second);
-                        if (millisTimeStamp == nullptr)
-                        {
-                            messages::internalError(asyncResp->res);
-                        }
-                        else
+                        if (millisTimeStamp != nullptr)
                         {
                             updateTimestamp =
                                 crow::utility::getTimestamp(*millisTimeStamp);
@@ -1584,22 +1565,15 @@
                     {
                         severity =
                             std::get_if<std::string>(&propertyMap.second);
-                        if (severity == nullptr)
-                        {
-                            messages::internalError(asyncResp->res);
-                        }
                     }
                     else if (propertyMap.first == "Message")
                     {
                         message = std::get_if<std::string>(&propertyMap.second);
-                        if (message == nullptr)
-                        {
-                            messages::internalError(asyncResp->res);
-                        }
                     }
                 }
                 if (id == nullptr || message == nullptr || severity == nullptr)
                 {
+                    messages::internalError(asyncResp->res);
                     return;
                 }
                 asyncResp->res.jsonValue = {