Fix status for non-existent JsonSchema FileGet

This will fix the incorrect status 500 to status 404 for the
non-eixstent JsonSchema FileGet.

```
% redfishtool raw GET  -r ${bmc}  -u root -p 0penBmc -S Always /redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.v1_99_1.json
   redfishtool: Transport: Response Error: status_code: 500 -- Internal Server Error
   redfishtool: raw: Error getting response
```

This commit also refactor `Response::openFile()` to return `ec` so that
the caller can check the reason of the failure.

Tested:
- Verify redfishtool result for the non-existent JsonSchema file like
```
% redfishtool raw GET  -r ${bmc}  -u root -p 0penBmc -S Always /redfish/v1/JsonSchemas/<schema>/<non-existent-schema>.json
   redfishtool: Transport: Response Error: status_code: 404 -- Not Found
   redfishtool: raw: Error getting response
```
- Redfish Service validator passes

Change-Id: I98927c076bb6e7dfb3742183b4b3545e328d2657
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/http/http_response.hpp b/http/http_response.hpp
index a4c8375..c411f88 100644
--- a/http/http_response.hpp
+++ b/http/http_response.hpp
@@ -21,6 +21,13 @@
 
 namespace http = boost::beast::http;
 
+enum class OpenCode
+{
+    Success,
+    FileDoesNotExist,
+    InternalError,
+};
+
 struct Response
 {
     template <typename Adaptor, typename Handler>
@@ -288,18 +295,23 @@
         expectedHash = hash;
     }
 
-    bool openFile(const std::filesystem::path& path,
-                  bmcweb::EncodingType enc = bmcweb::EncodingType::Raw)
+    OpenCode openFile(const std::filesystem::path& path,
+                      bmcweb::EncodingType enc = bmcweb::EncodingType::Raw)
     {
         boost::beast::error_code ec;
         response.body().open(path.c_str(), boost::beast::file_mode::read, ec);
         response.body().encodingType = enc;
         if (ec)
         {
-            BMCWEB_LOG_ERROR("Failed to open file {}", path.c_str());
-            return false;
+            BMCWEB_LOG_ERROR("Failed to open file {}, ec={}", path.c_str(),
+                             ec.value());
+            if (ec.value() == boost::system::errc::no_such_file_or_directory)
+            {
+                return OpenCode::FileDoesNotExist;
+            }
+            return OpenCode::InternalError;
         }
-        return true;
+        return OpenCode::Success;
     }
 
     bool openFd(int fd, bmcweb::EncodingType enc = bmcweb::EncodingType::Raw)
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 512c24e..fc074d6 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -2620,7 +2620,8 @@
 
                 for (const auto& file : files)
                 {
-                    if (!asyncResp->res.openFile(file))
+                    if (asyncResp->res.openFile(file) !=
+                        crow::OpenCode::Success)
                     {
                         continue;
                     }
diff --git a/include/webassets.hpp b/include/webassets.hpp
index 689c7d3..50981ea 100644
--- a/include/webassets.hpp
+++ b/include/webassets.hpp
@@ -100,7 +100,7 @@
         }
     }
 
-    if (!asyncResp->res.openFile(file.absolutePath))
+    if (asyncResp->res.openFile(file.absolutePath) != crow::OpenCode::Success)
     {
         BMCWEB_LOG_DEBUG("failed to read file");
         asyncResp->res.result(
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 5af8852..c8b01ea 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -2995,7 +2995,8 @@
                             return;
                         }
 
-                        if (!asyncResp->res.openFile(dbusFilepath))
+                        if (asyncResp->res.openFile(dbusFilepath) !=
+                            crow::OpenCode::Success)
                         {
                             messages::resourceNotFound(asyncResp->res,
                                                        "LogEntry", logID);
diff --git a/redfish-core/lib/redfish_v1.hpp b/redfish-core/lib/redfish_v1.hpp
index 7276809..418f66c 100644
--- a/redfish-core/lib/redfish_v1.hpp
+++ b/redfish-core/lib/redfish_v1.hpp
@@ -204,11 +204,16 @@
         return;
     }
 
-    if (!asyncResp->res.openFile(filepath))
+    crow::OpenCode ec = asyncResp->res.openFile(filepath);
+    if (ec == crow::OpenCode::FileDoesNotExist)
+    {
+        messages::resourceNotFound(asyncResp->res, "JsonSchemaFile", schema);
+        return;
+    }
+    if (ec == crow::OpenCode::InternalError)
     {
         BMCWEB_LOG_DEBUG("failed to read file");
-        asyncResp->res.result(
-            boost::beast::http::status::internal_server_error);
+        messages::internalError(asyncResp->res);
         return;
     }
 }