Improve the Redfish error reporting interface

Makes the Redfish error reporting interface automatically handle
setting the http status and JSON content in the response object.

When using an AsyncResp object, this allows for simply calling
the Redfish error and returning.

Change-Id: Icfdce2de763225f070e8dd61e591f296703f46bb
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
diff --git a/redfish-core/lib/redfish_sessions.hpp b/redfish-core/lib/redfish_sessions.hpp
index 4922724..b0a2948 100644
--- a/redfish-core/lib/redfish_sessions.hpp
+++ b/redfish-core/lib/redfish_sessions.hpp
@@ -54,11 +54,7 @@
 
         if (session == nullptr)
         {
-            messages::addMessageToErrorJson(
-                res.jsonValue,
-                messages::resourceNotFound("Session", params[0]));
-
-            res.result(boost::beast::http::status::not_found);
+            messages::resourceNotFound(res, "Session", params[0]);
             res.end();
             return;
         }
@@ -82,10 +78,7 @@
             BMCWEB_LOG_ERROR << "Session DELETE has been called with invalid "
                                 "number of params";
 
-            res.result(boost::beast::http::status::bad_request);
-            messages::addMessageToErrorJson(res.jsonValue,
-                                            messages::generalError());
-
+            messages::generalError(res);
             res.end();
             return;
         }
@@ -96,11 +89,7 @@
 
         if (session == nullptr)
         {
-            messages::addMessageToErrorJson(
-                res.jsonValue,
-                messages::resourceNotFound("Session", params[0]));
-
-            res.result(boost::beast::http::status::not_found);
+            messages::resourceNotFound(res, "Session", params[0]);
             res.end();
             return;
         }
@@ -182,16 +171,12 @@
         {
             if (username.empty())
             {
-                res.result(boost::beast::http::status::bad_request);
-                messages::addMessageToErrorJson(
-                    res.jsonValue, messages::propertyMissing("UserName"));
+                messages::propertyMissing(res, "UserName", "UserName");
             }
 
             if (password.empty())
             {
-                res.result(boost::beast::http::status::bad_request);
-                messages::addMessageToErrorJson(
-                    res.jsonValue, messages::propertyMissing("Password"));
+                messages::propertyMissing(res, "Password", "Password");
             }
             res.end();
 
@@ -200,12 +185,8 @@
 
         if (!pamAuthenticateUser(username, password))
         {
-
-            res.result(boost::beast::http::status::unauthorized);
-            messages::addMessageToErrorJson(
-                res.jsonValue,
-                messages::resourceAtUriUnauthorized(
-                    std::string(req.url), "Invalid username or password"));
+            messages::resourceAtUriUnauthorized(res, std::string(req.url),
+                                                "Invalid username or password");
             res.end();
 
             return;