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/account_service.hpp b/redfish-core/lib/account_service.hpp
index cc37591..4e5d676 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -103,8 +103,7 @@
                         const ManagedObjectType& users) {
                 if (ec)
                 {
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
 
@@ -153,10 +152,7 @@
         const char* priv = getRoleIdFromPrivilege(*roleId);
         if (priv == nullptr)
         {
-            messages::addMessageToErrorJson(
-                res.jsonValue,
-                messages::propertyValueNotInList(*roleId, "RoleId"));
-            res.result(boost::beast::http::status::bad_request);
+            messages::propertyValueNotInList(asyncResp->res, *roleId, "RoleId");
             return;
         }
         roleId = priv;
@@ -166,13 +162,9 @@
                 const boost::system::error_code ec) {
                 if (ec)
                 {
-                    messages::addMessageToErrorJson(
-                        asyncResp->res.jsonValue,
-                        messages::resourceAlreadyExists(
-                            "#ManagerAccount.v1_0_3.ManagerAccount", "UserName",
-                            username));
-                    asyncResp->res.result(
-                        boost::beast::http::status::bad_request);
+                    messages::resourceAlreadyExists(
+                        asyncResp->res, "#ManagerAccount.v1_0_3.ManagerAccount",
+                        "UserName", username);
                     return;
                 }
 
@@ -185,14 +177,11 @@
                         [asyncResp](const boost::system::error_code ec) {
                             if (ec)
                             {
-                                asyncResp->res.result(
-                                    boost::beast::http::status::
-                                        internal_server_error);
+                                messages::internalError(asyncResp->res);
                                 return;
                             }
 
-                            asyncResp->res.result(
-                                boost::beast::http::status::bad_request);
+                            messages::invalidObject(asyncResp->res, "Password");
                         },
                         "xyz.openbmc_project.User.Manager",
                         "/xyz/openbmc_project/user/" + username,
@@ -202,8 +191,7 @@
                     return;
                 }
 
-                messages::addMessageToJsonRoot(asyncResp->res.jsonValue,
-                                               messages::created());
+                messages::created(asyncResp->res);
                 asyncResp->res.addHeader(
                     "Location",
                     "/redfish/v1/AccountService/Accounts/" + username);
@@ -291,7 +279,7 @@
 
         if (params.size() != 1)
         {
-            res.result(boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
 
@@ -301,8 +289,7 @@
                 const ManagedObjectType& users) {
                 if (ec)
                 {
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
 
@@ -371,7 +358,8 @@
                     }
                 }
 
-                asyncResp->res.result(boost::beast::http::status::not_found);
+                messages::resourceNotFound(asyncResp->res, "ManagerAccount",
+                                           accountName);
             },
             "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
             "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
@@ -383,7 +371,7 @@
         auto asyncResp = std::make_shared<AsyncResp>(res);
         if (params.size() != 1)
         {
-            res.result(boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
 
@@ -402,13 +390,9 @@
              enabled(std::move(enabled)), asyncResp](bool userExists) {
                 if (!userExists)
                 {
-                    messages::addMessageToErrorJson(
-                        asyncResp->res.jsonValue,
-                        messages::resourceNotFound(
-                            "#ManagerAccount.v1_0_3.ManagerAccount", username));
-
-                    asyncResp->res.result(
-                        boost::beast::http::status::not_found);
+                    messages::resourceNotFound(
+                        asyncResp->res, "#ManagerAccount.v1_0_3.ManagerAccount",
+                        username);
                     return;
                 }
 
@@ -417,8 +401,7 @@
                     if (!pamUpdatePassword(username, *password))
                     {
                         BMCWEB_LOG_ERROR << "pamUpdatePassword Failed";
-                        asyncResp->res.result(
-                            boost::beast::http::status::internal_server_error);
+                        messages::internalError(asyncResp->res);
                         return;
                     }
                 }
@@ -431,17 +414,13 @@
                             {
                                 BMCWEB_LOG_ERROR << "D-Bus responses error: "
                                                  << ec;
-                                asyncResp->res.result(
-                                    boost::beast::http::status::
-                                        internal_server_error);
+                                messages::internalError(asyncResp->res);
                                 return;
                             }
                             // TODO Consider support polling mechanism to
                             // verify status of host and chassis after
                             // execute the requested action.
-                            BMCWEB_LOG_DEBUG << "Response with no content";
-                            asyncResp->res.result(
-                                boost::beast::http::status::no_content);
+                            messages::success(asyncResp->res);
                         },
                         "xyz.openbmc_project.User.Manager",
                         "/xyz/openbmc_project/users/" + username,
@@ -460,7 +439,7 @@
 
         if (params.size() != 1)
         {
-            res.result(boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
 
@@ -471,17 +450,13 @@
                 const boost::system::error_code ec) {
                 if (ec)
                 {
-                    messages::addMessageToErrorJson(
-                        asyncResp->res.jsonValue,
-                        messages::resourceNotFound(
-                            "#ManagerAccount.v1_0_3.ManagerAccount", username));
-                    asyncResp->res.result(
-                        boost::beast::http::status::not_found);
+                    messages::resourceNotFound(
+                        asyncResp->res, "#ManagerAccount.v1_0_3.ManagerAccount",
+                        username);
                     return;
                 }
 
-                messages::addMessageToJsonRoot(asyncResp->res.jsonValue,
-                                               messages::accountRemoved());
+                messages::accountRemoved(asyncResp->res);
             },
             "xyz.openbmc_project.User.Manager", userPath,
             "xyz.openbmc_project.Object.Delete", "Delete");
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
index fa10d5c..6615760 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -80,10 +80,7 @@
                         const std::vector<std::string> &chassisList) {
                 if (ec)
                 {
-                    messages::addMessageToErrorJson(asyncResp->res.jsonValue,
-                                                    messages::internalError());
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
                 nlohmann::json &chassisArray =
@@ -148,7 +145,7 @@
         // impossible.
         if (params.size() != 1)
         {
-            res.result(boost::beast::http::status::internal_server_error);
+            messages::internalError(res);
             res.end();
             return;
         }
@@ -165,10 +162,7 @@
                     &subtree) {
                 if (ec)
                 {
-                    messages::addMessageToErrorJson(asyncResp->res.jsonValue,
-                                                    messages::internalError());
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
                 // Iterate over all retrieved ObjectPaths.
@@ -226,9 +220,8 @@
                 }
 
                 // Couldn't find an object with that name.  return an error
-                asyncResp->res.jsonValue = redfish::messages::resourceNotFound(
-                    "#Chassis.v1_4_0.Chassis", chassisId);
-                asyncResp->res.result(boost::beast::http::status::not_found);
+                messages::resourceNotFound(
+                    asyncResp->res, "#Chassis.v1_4_0.Chassis", chassisId);
             },
             "xyz.openbmc_project.ObjectMapper",
             "/xyz/openbmc_project/object_mapper",
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index da4df20..7da7d0a 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -480,9 +480,9 @@
                         const boost::system::error_code ec) {
         if (ec)
         {
-            messages::addMessageToJson(
-                asyncResp->res.jsonValue, messages::internalError(),
-                "/IPv4Addresses/" + std::to_string(ipIdx) + "/" + name);
+            messages::internalError(asyncResp->res, "/IPv4Addresses/" +
+                                                        std::to_string(ipIdx) +
+                                                        "/" + name);
         }
         else
         {
@@ -522,9 +522,9 @@
                         const boost::system::error_code ec) {
         if (ec)
         {
-            messages::addMessageToJson(
-                asyncResp->res.jsonValue, messages::internalError(),
-                "/IPv4Addresses/" + std::to_string(ipIdx) + "/AddressOrigin");
+            messages::internalError(asyncResp->res, "/IPv4Addresses/" +
+                                                        std::to_string(ipIdx) +
+                                                        "/AddressOrigin");
         }
         else
         {
@@ -564,9 +564,9 @@
                         const boost::system::error_code ec) {
         if (ec)
         {
-            messages::addMessageToJson(
-                asyncResp->res.jsonValue, messages::internalError(),
-                "/IPv4Addresses/" + std::to_string(ipIdx) + "/SubnetMask");
+            messages::internalError(asyncResp->res, "/IPv4Addresses/" +
+                                                        std::to_string(ipIdx) +
+                                                        "/SubnetMask");
         }
         else
         {
@@ -620,9 +620,9 @@
         [ipIdx, asyncResp](const boost::system::error_code ec) {
             if (ec)
             {
-                messages::addMessageToJson(
-                    asyncResp->res.jsonValue, messages::internalError(),
-                    "/IPv4Addresses/" + std::to_string(ipIdx) + "/");
+                messages::internalError(asyncResp->res,
+                                        "/IPv4Addresses/" +
+                                            std::to_string(ipIdx) + "/");
             }
             else
             {
@@ -653,9 +653,9 @@
                             asyncResp](const boost::system::error_code ec) {
         if (ec)
         {
-            messages::addMessageToJson(
-                asyncResp->res.jsonValue, messages::internalError(),
-                "/IPv4Addresses/" + std::to_string(ipIdx) + "/");
+            messages::internalError(asyncResp->res, "/IPv4Addresses/" +
+                                                        std::to_string(ipIdx) +
+                                                        "/");
         }
     };
 
@@ -805,31 +805,31 @@
         res.jsonValue = Node::json;
         // Get eth interface list, and call the below callback for JSON
         // preparation
-        getEthernetIfaceList([&res](
-                                 const bool &success,
-                                 const std::vector<std::string> &iface_list) {
-            if (!success)
-            {
-                res.result(boost::beast::http::status::internal_server_error);
+        getEthernetIfaceList(
+            [&res](const bool &success,
+                   const std::vector<std::string> &iface_list) {
+                if (!success)
+                {
+                    messages::internalError(res);
+                    res.end();
+                    return;
+                }
+
+                nlohmann::json &iface_array = res.jsonValue["Members"];
+                iface_array = nlohmann::json::array();
+                for (const std::string &iface_item : iface_list)
+                {
+                    iface_array.push_back(
+                        {{"@odata.id",
+                          "/redfish/v1/Managers/bmc/EthernetInterfaces/" +
+                              iface_item}});
+                }
+
+                res.jsonValue["Members@odata.count"] = iface_array.size();
+                res.jsonValue["@odata.id"] =
+                    "/redfish/v1/Managers/bmc/EthernetInterfaces";
                 res.end();
-                return;
-            }
-
-            nlohmann::json &iface_array = res.jsonValue["Members"];
-            iface_array = nlohmann::json::array();
-            for (const std::string &iface_item : iface_list)
-            {
-                iface_array.push_back(
-                    {{"@odata.id",
-                      "/redfish/v1/Managers/bmc/EthernetInterfaces/" +
-                          iface_item}});
-            }
-
-            res.jsonValue["Members@odata.count"] = iface_array.size();
-            res.jsonValue["@odata.id"] =
-                "/redfish/v1/Managers/bmc/EthernetInterfaces";
-            res.end();
-        });
+            });
     }
 };
 
@@ -871,45 +871,37 @@
     {
         if (!input.is_object())
         {
-            messages::addMessageToJson(
-                asyncResp->res.jsonValue,
-                messages::propertyValueTypeError(input.dump(), "VLAN"), "/");
+            messages::propertyValueTypeError(asyncResp->res, input.dump(),
+                                             "VLAN", "/");
             return;
         }
 
         nlohmann::json::const_iterator vlanEnable = input.find("VLANEnable");
         if (vlanEnable == input.end())
         {
-            messages::addMessageToJson(asyncResp->res.jsonValue,
-                                       messages::propertyMissing("VLANEnable"),
-                                       "/VLANEnable");
+            messages::propertyMissing(asyncResp->res, "VLANEnable",
+                                      "/VLANEnable");
             return;
         }
         const bool *vlanEnableBool = vlanEnable->get_ptr<const bool *>();
         if (vlanEnableBool == nullptr)
         {
-            messages::addMessageToJson(asyncResp->res.jsonValue,
-                                       messages::propertyValueTypeError(
-                                           vlanEnable->dump(), "VLANEnable"),
-                                       "/VLANEnable");
+            messages::propertyValueTypeError(asyncResp->res, vlanEnable->dump(),
+                                             "VLANEnable", "/VLANEnable");
             return;
         }
 
         nlohmann::json::const_iterator vlanId = input.find("VLANId");
         if (vlanId == input.end())
         {
-            messages::addMessageToJson(asyncResp->res.jsonValue,
-                                       messages::propertyMissing("VLANId"),
-                                       "/VLANId");
+            messages::propertyMissing(asyncResp->res, "VLANId", "/VLANId");
             return;
         }
         const uint64_t *vlanIdUint = vlanId->get_ptr<const uint64_t *>();
         if (vlanIdUint == nullptr)
         {
-            messages::addMessageToJson(
-                asyncResp->res.jsonValue,
-                messages::propertyValueTypeError(vlanId->dump(), "VLANId"),
-                "/VLANId");
+            messages::propertyValueTypeError(asyncResp->res, vlanId->dump(),
+                                             "VLANId", "/VLANId");
             return;
         }
 
@@ -917,9 +909,8 @@
         {
             // This interface is not a VLAN. Cannot do anything with it
             // TODO(kkowalsk) Change this message
-            messages::addMessageToJson(
-                asyncResp->res.jsonValue,
-                messages::propertyNotWritable("VLANEnable"), "/VLANEnable");
+            messages::propertyNotWritable(asyncResp->res, "VLANEnable",
+                                          "/VLANEnable");
 
             return;
         }
@@ -932,8 +923,7 @@
             auto callback = [asyncResp](const boost::system::error_code ec) {
                 if (ec)
                 {
-                    messages::addMessageToJson(asyncResp->res.jsonValue,
-                                               messages::internalError(), "/");
+                    messages::internalError(asyncResp->res);
                 }
                 else
                 {
@@ -952,8 +942,7 @@
             auto callback = [asyncResp](const boost::system::error_code ec) {
                 if (ec)
                 {
-                    messages::addMessageToJson(asyncResp->res.jsonValue,
-                                               messages::internalError(), "/");
+                    messages::internalError(asyncResp->res);
                     return;
                 }
                 asyncResp->res.jsonValue["VLANEnable"] = false;
@@ -973,10 +962,8 @@
         const std::string *newHostname = input.get_ptr<const std::string *>();
         if (newHostname == nullptr)
         {
-            messages::addMessageToJson(
-                asyncResp->res.jsonValue,
-                messages::propertyValueTypeError(input.dump(), "HostName"),
-                "/HostName");
+            messages::propertyValueTypeError(asyncResp->res, input.dump(),
+                                             "HostName", "/HostName");
             return;
         }
 
@@ -986,9 +973,7 @@
                               const boost::system::error_code ec) {
                 if (ec)
                 {
-                    messages::addMessageToJson(asyncResp->res.jsonValue,
-                                               messages::internalError(),
-                                               "/HostName");
+                    messages::internalError(asyncResp->res, "/HostName");
                 }
                 else
                 {
@@ -1004,10 +989,8 @@
     {
         if (!input.is_array())
         {
-            messages::addMessageToJson(
-                asyncResp->res.jsonValue,
-                messages::propertyValueTypeError(input.dump(), "IPv4Addresses"),
-                "/IPv4Addresses");
+            messages::propertyValueTypeError(asyncResp->res, input.dump(),
+                                             "IPv4Addresses", "/IPv4Addresses");
             return;
         }
 
@@ -1016,9 +999,7 @@
         {
             // TODO(kkowalsk) This should be a message indicating that not
             // enough data has been provided
-            messages::addMessageToJson(asyncResp->res.jsonValue,
-                                       messages::internalError(),
-                                       "/IPv4Addresses");
+            messages::internalError(asyncResp->res, "/IPv4Addresses");
             return;
         }
 
@@ -1032,10 +1013,8 @@
             // Check that entry is not of some unexpected type
             if (!thisJson.is_object() && !thisJson.is_null())
             {
-                messages::addMessageToJson(asyncResp->res.jsonValue,
-                                           messages::propertyValueTypeError(
-                                               thisJson.dump(), "IPv4Address"),
-                                           pathString);
+                messages::propertyValueTypeError(
+                    asyncResp->res, thisJson.dump(), "IPv4Address", pathString);
 
                 continue;
             }
@@ -1048,10 +1027,8 @@
                 addressField = addressFieldIt->get_ptr<const std::string *>();
                 if (addressField == nullptr)
                 {
-                    messages::addMessageToJson(
-                        asyncResp->res.jsonValue,
-                        messages::propertyValueFormatError(
-                            addressFieldIt->dump(), "Address"),
+                    messages::propertyValueFormatError(
+                        asyncResp->res, addressFieldIt->dump(), "Address",
                         pathString + "/Address");
                     continue;
                 }
@@ -1059,10 +1036,8 @@
                 {
                     if (!ipv4VerifyIpAndGetBitcount(*addressField))
                     {
-                        messages::addMessageToJson(
-                            asyncResp->res.jsonValue,
-                            messages::propertyValueFormatError(*addressField,
-                                                               "Address"),
+                        messages::propertyValueFormatError(
+                            asyncResp->res, *addressField, "Address",
                             pathString + "/Address");
                         continue;
                     }
@@ -1078,10 +1053,8 @@
                 subnetField = subnetFieldIt->get_ptr<const std::string *>();
                 if (subnetField == nullptr)
                 {
-                    messages::addMessageToJson(
-                        asyncResp->res.jsonValue,
-                        messages::propertyValueFormatError(*subnetField,
-                                                           "SubnetMask"),
+                    messages::propertyValueFormatError(
+                        asyncResp->res, *subnetField, "SubnetMask",
                         pathString + "/SubnetMask");
                     continue;
                 }
@@ -1091,10 +1064,8 @@
                     if (!ipv4VerifyIpAndGetBitcount(*subnetField,
                                                     &*prefixLength))
                     {
-                        messages::addMessageToJson(
-                            asyncResp->res.jsonValue,
-                            messages::propertyValueFormatError(*subnetField,
-                                                               "SubnetMask"),
+                        messages::propertyValueFormatError(
+                            asyncResp->res, *subnetField, "SubnetMask",
                             pathString + "/SubnetMask");
                         continue;
                     }
@@ -1111,10 +1082,8 @@
                     addressOriginFieldIt->get_ptr<const std::string *>();
                 if (addressOriginField == nullptr)
                 {
-                    messages::addMessageToJson(
-                        asyncResp->res.jsonValue,
-                        messages::propertyValueFormatError(*addressOriginField,
-                                                           "AddressOrigin"),
+                    messages::propertyValueFormatError(
+                        asyncResp->res, *addressOriginField, "AddressOrigin",
                         pathString + "/AddressOrigin");
                     continue;
                 }
@@ -1126,11 +1095,9 @@
                             *addressOriginField);
                     if (addressOriginInDBusFormat.empty())
                     {
-                        messages::addMessageToJson(
-                            asyncResp->res.jsonValue,
-                            messages::propertyValueNotInList(
-                                *addressOriginField, "AddressOrigin"),
-                            pathString + "/AddressOrigin");
+                        messages::propertyValueNotInList(
+                            asyncResp->res, *addressOriginField,
+                            "AddressOrigin", pathString + "/AddressOrigin");
                         continue;
                     }
                 }
@@ -1146,11 +1113,9 @@
                 if (gatewayField == nullptr ||
                     !ipv4VerifyIpAndGetBitcount(*gatewayField))
                 {
-                    messages::addMessageToJson(
-                        asyncResp->res.jsonValue,
-                        messages::propertyValueFormatError(*gatewayField,
-                                                           "Gateway"),
-                        pathString + "/Gateway");
+                    messages::propertyValueFormatError(asyncResp->res,
+                                                       *gatewayField, "Gateway",
+                                                       pathString + "/Gateway");
                     continue;
                 }
             }
@@ -1167,10 +1132,9 @@
                                         const boost::system::error_code ec) {
                         if (ec)
                         {
-                            messages::addMessageToJson(
-                                asyncResp->res.jsonValue,
-                                messages::internalError(),
-                                "/IPv4Addresses/" + entryIdx + "/");
+                            messages::internalError(asyncResp->res,
+                                                    "/IPv4Addresses/" +
+                                                        entryIdx + "/");
                             return;
                         }
                         asyncResp->res.jsonValue["IPv4Addresses"][entryIdx] =
@@ -1193,9 +1157,8 @@
                                 const boost::system::error_code ec) {
                                 if (ec)
                                 {
-                                    messages::addMessageToJson(
-                                        asyncResp->res.jsonValue,
-                                        messages::internalError(),
+                                    messages::internalError(
+                                        asyncResp->res,
                                         "/IPv4Addresses/" +
                                             std::to_string(entryIdx) +
                                             "/Address");
@@ -1239,9 +1202,8 @@
                                 const boost::system::error_code ec) {
                                 if (ec)
                                 {
-                                    messages::addMessageToJson(
-                                        asyncResp->res.jsonValue,
-                                        messages::internalError(),
+                                    messages::internalError(
+                                        asyncResp->res,
                                         "/IPv4Addresses/" +
                                             std::to_string(entryIdx) +
                                             "/Gateway");
@@ -1270,28 +1232,22 @@
                 // Create IPv4 with provided data
                 if (gatewayField == nullptr)
                 {
-                    messages::addMessageToJson(
-                        asyncResp->res.jsonValue,
-                        messages::propertyMissing("Gateway"),
-                        pathString + "/Gateway");
+                    messages::propertyMissing(asyncResp->res, "Gateway",
+                                              pathString + "/Gateway");
                     continue;
                 }
 
                 if (addressField == nullptr)
                 {
-                    messages::addMessageToJson(
-                        asyncResp->res.jsonValue,
-                        messages::propertyMissing("Address"),
-                        pathString + "/Address");
+                    messages::propertyMissing(asyncResp->res, "Address",
+                                              pathString + "/Address");
                     continue;
                 }
 
                 if (!prefixLength)
                 {
-                    messages::addMessageToJson(
-                        asyncResp->res.jsonValue,
-                        messages::propertyMissing("SubnetMask"),
-                        pathString + "/SubnetMask");
+                    messages::propertyMissing(asyncResp->res, "SubnetMask",
+                                              pathString + "/SubnetMask");
                     continue;
                 }
 
@@ -1365,8 +1321,7 @@
         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
         if (params.size() != 1)
         {
-            asyncResp->res.result(
-                boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
 
@@ -1379,12 +1334,8 @@
                 {
                     // TODO(Pawel)consider distinguish between non existing
                     // object, and other errors
-                    messages::addMessageToErrorJson(
-                        asyncResp->res.jsonValue,
-                        messages::resourceNotFound("EthernetInterface",
-                                                   iface_id));
-                    asyncResp->res.result(
-                        boost::beast::http::status::not_found);
+                    messages::resourceNotFound(asyncResp->res,
+                                               "EthernetInterface", iface_id);
                     return;
                 }
                 asyncResp->res.jsonValue =
@@ -1398,7 +1349,7 @@
         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
         if (params.size() != 1)
         {
-            res.result(boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
 
@@ -1422,14 +1373,8 @@
                     // ... otherwise return error
                     // TODO(Pawel)consider distinguish between non existing
                     // object, and other errors
-                    messages::addMessageToErrorJson(
-                        asyncResp->res.jsonValue,
-                        messages::resourceNotFound("VLAN Network Interface",
-                                                   iface_id));
-                    asyncResp->res.result(
-                        boost::beast::http::status::not_found);
-                    asyncResp->res.end();
-
+                    messages::resourceNotFound(
+                        asyncResp->res, "VLAN Network Interface", iface_id);
                     return;
                 }
 
@@ -1455,9 +1400,8 @@
                     else if (propertyIt.key() == "IPv6Addresses")
                     {
                         // TODO(kkowalsk) IPv6 Not supported on D-Bus yet
-                        messages::addMessageToJsonRoot(
-                            asyncResp->res.jsonValue,
-                            messages::propertyNotWritable(propertyIt.key()));
+                        messages::propertyNotWritable(
+                            asyncResp->res, propertyIt.key(), propertyIt.key());
                     }
                     else
                     {
@@ -1467,17 +1411,16 @@
                         if (fieldInJsonIt == asyncResp->res.jsonValue.end())
                         {
                             // Field not in scope of defined fields
-                            messages::addMessageToJsonRoot(
-                                asyncResp->res.jsonValue,
-                                messages::propertyUnknown(propertyIt.key()));
+                            messages::propertyUnknown(asyncResp->res,
+                                                      propertyIt.key(),
+                                                      propertyIt.key());
                         }
                         else
                         {
                             // User attempted to modify non-writable field
-                            messages::addMessageToJsonRoot(
-                                asyncResp->res.jsonValue,
-                                messages::propertyNotWritable(
-                                    propertyIt.key()));
+                            messages::propertyNotWritable(asyncResp->res,
+                                                          propertyIt.key(),
+                                                          propertyIt.key());
                         }
                     }
                 }
@@ -1546,14 +1489,11 @@
     bool verifyNames(crow::Response &res, const std::string &parent,
                      const std::string &iface)
     {
+        std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
         if (!boost::starts_with(iface, parent + "_"))
         {
-            messages::addMessageToErrorJson(
-                res.jsonValue,
-                messages::resourceNotFound("VLAN Network Interface", iface));
-            res.result(boost::beast::http::status::not_found);
-            res.end();
-
+            messages::resourceNotFound(asyncResp->res, "VLAN Network Interface",
+                                       iface);
             return false;
         }
         else
@@ -1575,7 +1515,7 @@
         // impossible.
         if (params.size() != 2)
         {
-            res.result(boost::beast::http::status::internal_server_error);
+            messages::internalError(res);
             res.end();
             return;
         }
@@ -1605,12 +1545,8 @@
                     // ... otherwise return error
                     // TODO(Pawel)consider distinguish between non existing
                     // object, and other errors
-                    messages::addMessageToErrorJson(
-                        asyncResp->res.jsonValue,
-                        messages::resourceNotFound("VLAN Network Interface",
-                                                   iface_id));
-                    asyncResp->res.result(
-                        boost::beast::http::status::not_found);
+                    messages::resourceNotFound(
+                        asyncResp->res, "VLAN Network Interface", iface_id);
                 }
             });
     }
@@ -1621,8 +1557,7 @@
         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
         if (params.size() != 2)
         {
-            asyncResp->res.result(
-                boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
 
@@ -1652,13 +1587,8 @@
                 {
                     // TODO(Pawel)consider distinguish between non existing
                     // object, and other errors
-                    messages::addMessageToErrorJson(
-                        asyncResp->res.jsonValue,
-                        messages::resourceNotFound("VLAN Network Interface",
-                                                   ifaceId));
-                    asyncResp->res.result(
-                        boost::beast::http::status::not_found);
-                    asyncResp->res.end();
+                    messages::resourceNotFound(
+                        asyncResp->res, "VLAN Network Interface", ifaceId);
 
                     return;
                 }
@@ -1676,17 +1606,16 @@
                         if (fieldInJsonIt == asyncResp->res.jsonValue.end())
                         {
                             // Field not in scope of defined fields
-                            messages::addMessageToJsonRoot(
-                                asyncResp->res.jsonValue,
-                                messages::propertyUnknown(propertyIt.key()));
+                            messages::propertyUnknown(asyncResp->res,
+                                                      propertyIt.key(),
+                                                      propertyIt.key());
                         }
                         else
                         {
                             // User attempted to modify non-writable field
-                            messages::addMessageToJsonRoot(
-                                asyncResp->res.jsonValue,
-                                messages::propertyNotWritable(
-                                    propertyIt.key()));
+                            messages::propertyNotWritable(asyncResp->res,
+                                                          propertyIt.key(),
+                                                          propertyIt.key());
                         }
                     }
                 }
@@ -1702,8 +1631,7 @@
         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
         if (params.size() != 2)
         {
-            asyncResp->res.result(
-                boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
 
@@ -1717,49 +1645,38 @@
 
         // Get single eth interface data, and call the below callback for JSON
         // preparation
-        getEthernetIfaceData(ifaceId, [this, asyncResp,
-                                       parentIfaceId{
-                                           std::string(parentIfaceId)},
-                                       ifaceId{std::string(ifaceId)}](
-                                          const bool &success,
-                                          const EthernetInterfaceData &ethData,
-                                          const boost::container::flat_set<
-                                              IPv4AddressData> &ipv4Data) {
-            if (success && ethData.vlan_id)
-            {
-                asyncResp->res.jsonValue = parseInterfaceData(
-                    parentIfaceId, ifaceId, ethData, ipv4Data);
+        getEthernetIfaceData(
+            ifaceId,
+            [this, asyncResp, parentIfaceId{std::string(parentIfaceId)},
+             ifaceId{std::string(ifaceId)}](
+                const bool &success, const EthernetInterfaceData &ethData,
+                const boost::container::flat_set<IPv4AddressData> &ipv4Data) {
+                if (success && ethData.vlan_id)
+                {
+                    asyncResp->res.jsonValue = parseInterfaceData(
+                        parentIfaceId, ifaceId, ethData, ipv4Data);
 
-                auto callback = [asyncResp](
-                                    const boost::system::error_code ec) {
-                    if (ec)
-                    {
-                        messages::addMessageToErrorJson(
-                            asyncResp->res.jsonValue,
-                            messages::internalError());
-                        asyncResp->res.result(
-                            boost::beast::http::status::internal_server_error);
-                    }
-                };
-                crow::connections::systemBus->async_method_call(
-                    std::move(callback), "xyz.openbmc_project.Network",
-                    std::string("/xyz/openbmc_project/network/") + ifaceId,
-                    "xyz.openbmc_project.Object.Delete", "Delete");
-            }
-            else
-            {
-                // ... otherwise return error
-                // TODO(Pawel)consider distinguish between non existing object,
-                // and
-                // other errors
-                messages::addMessageToErrorJson(
-                    asyncResp->res.jsonValue,
-                    messages::resourceNotFound("VLAN Network Interface",
-                                               ifaceId));
-                asyncResp->res.result(boost::beast::http::status::not_found);
-                asyncResp->res.end();
-            }
-        });
+                    auto callback =
+                        [asyncResp](const boost::system::error_code ec) {
+                            if (ec)
+                            {
+                                messages::internalError(asyncResp->res);
+                            }
+                        };
+                    crow::connections::systemBus->async_method_call(
+                        std::move(callback), "xyz.openbmc_project.Network",
+                        std::string("/xyz/openbmc_project/network/") + ifaceId,
+                        "xyz.openbmc_project.Object.Delete", "Delete");
+                }
+                else
+                {
+                    // ... otherwise return error
+                    // TODO(Pawel)consider distinguish between non existing
+                    // object, and other errors
+                    messages::resourceNotFound(
+                        asyncResp->res, "VLAN Network Interface", ifaceId);
+                }
+            });
     }
 };
 
@@ -1805,8 +1722,7 @@
         if (params.size() != 1)
         {
             // This means there is a problem with the router
-            asyncResp->res.result(
-                boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
 
@@ -1814,48 +1730,44 @@
 
         // Get eth interface list, and call the below callback for JSON
         // preparation
-        getEthernetIfaceList([this, asyncResp,
-                              rootInterfaceName{
-                                  std::string(rootInterfaceName)}](
-                                 const bool &success,
-                                 const std::vector<std::string> &iface_list) {
-            if (!success)
-            {
-                asyncResp->res.result(
-                    boost::beast::http::status::internal_server_error);
-                return;
-            }
-            asyncResp->res.jsonValue = Node::json;
-
-            nlohmann::json iface_array = nlohmann::json::array();
-
-            for (const std::string &iface_item : iface_list)
-            {
-                if (boost::starts_with(iface_item, rootInterfaceName + "_"))
+        getEthernetIfaceList(
+            [this, asyncResp,
+             rootInterfaceName{std::string(rootInterfaceName)}](
+                const bool &success,
+                const std::vector<std::string> &iface_list) {
+                if (!success)
                 {
-                    iface_array.push_back(
-                        {{"@odata.id",
-                          "/redfish/v1/Managers/bmc/EthernetInterfaces/" +
-                              rootInterfaceName + "/VLANs/" + iface_item}});
+                    messages::internalError(asyncResp->res);
+                    return;
                 }
-            }
+                asyncResp->res.jsonValue = Node::json;
 
-            if (iface_array.empty())
-            {
-                messages::addMessageToErrorJson(
-                    asyncResp->res.jsonValue,
-                    messages::resourceNotFound("EthernetInterface",
-                                               rootInterfaceName));
-                asyncResp->res.result(boost::beast::http::status::not_found);
-                return;
-            }
-            asyncResp->res.jsonValue["Members@odata.count"] =
-                iface_array.size();
-            asyncResp->res.jsonValue["Members"] = std::move(iface_array);
-            asyncResp->res.jsonValue["@odata.id"] =
-                "/redfish/v1/Managers/bmc/EthernetInterfaces/" +
-                rootInterfaceName + "/VLANs";
-        });
+                nlohmann::json iface_array = nlohmann::json::array();
+
+                for (const std::string &iface_item : iface_list)
+                {
+                    if (boost::starts_with(iface_item, rootInterfaceName + "_"))
+                    {
+                        iface_array.push_back(
+                            {{"@odata.id",
+                              "/redfish/v1/Managers/bmc/EthernetInterfaces/" +
+                                  rootInterfaceName + "/VLANs/" + iface_item}});
+                    }
+                }
+
+                if (iface_array.empty())
+                {
+                    messages::resourceNotFound(
+                        asyncResp->res, "EthernetInterface", rootInterfaceName);
+                    return;
+                }
+                asyncResp->res.jsonValue["Members@odata.count"] =
+                    iface_array.size();
+                asyncResp->res.jsonValue["Members"] = std::move(iface_array);
+                asyncResp->res.jsonValue["@odata.id"] =
+                    "/redfish/v1/Managers/bmc/EthernetInterfaces/" +
+                    rootInterfaceName + "/VLANs";
+            });
     }
 
     void doPost(crow::Response &res, const crow::Request &req,
@@ -1864,8 +1776,7 @@
         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
         if (params.size() != 1)
         {
-            asyncResp->res.result(
-                boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
 
@@ -1878,19 +1789,15 @@
         auto vlanIdJson = json.find("VLANId");
         if (vlanIdJson == json.end())
         {
-            messages::addMessageToJson(asyncResp->res.jsonValue,
-                                       messages::propertyMissing("VLANId"),
-                                       "/VLANId");
+            messages::propertyMissing(asyncResp->res, "VLANId", "/VLANId");
             return;
         }
 
         const uint64_t *vlanId = vlanIdJson->get_ptr<const uint64_t *>();
         if (vlanId == nullptr)
         {
-            messages::addMessageToJson(
-                asyncResp->res.jsonValue,
-                messages::propertyValueTypeError(vlanIdJson->dump(), "VLANId"),
-                "/VLANId");
+            messages::propertyValueTypeError(asyncResp->res, vlanIdJson->dump(),
+                                             "VLANId", "/VLANId");
             return;
         }
         const std::string &rootInterfaceName = params[0];
@@ -1900,13 +1807,10 @@
             {
                 // TODO(ed) make more consistent error messages based on
                 // phosphor-network responses
-                messages::addMessageToErrorJson(asyncResp->res.jsonValue,
-                                                messages::internalError());
+                messages::internalError(asyncResp->res);
                 return;
             }
-            asyncResp->res.result(boost::beast::http::status::created);
-            messages::addMessageToErrorJson(asyncResp->res.jsonValue,
-                                            messages::created());
+            messages::created(asyncResp->res);
         };
         crow::connections::systemBus->async_method_call(
             std::move(callback), "xyz.openbmc_project.Network",
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index ee342cf..562bbfc 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -260,8 +260,7 @@
         if (ret < 0)
         {
             BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
-            asyncResp->res.result(
-                boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
         std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
@@ -302,8 +301,7 @@
             nlohmann::json &bmcLogEntry = logEntryArray.back();
             if (fillBMCLogEntryJson(idStr, journal.get(), bmcLogEntry) != 0)
             {
-                asyncResp->res.result(
-                    boost::beast::http::status::internal_server_error);
+                messages::internalError(asyncResp->res);
                 return;
             }
         }
@@ -334,8 +332,7 @@
         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
         if (params.size() != 1)
         {
-            asyncResp->res.result(
-                boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
         // Convert the unique ID back to a timestamp to find the entry
@@ -364,8 +361,7 @@
         if (ret < 0)
         {
             BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
-            asyncResp->res.result(
-                boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
         std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
@@ -380,8 +376,7 @@
         if (fillBMCLogEntryJson(params[0], journal.get(),
                                 asyncResp->res.jsonValue) != 0)
         {
-            asyncResp->res.result(
-                boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
     }
@@ -482,8 +477,7 @@
                 {
                     BMCWEB_LOG_DEBUG << "failed to get entries ec: "
                                      << ec.message();
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
             }
@@ -570,8 +564,7 @@
         std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
         if (params.size() != 1)
         {
-            asyncResp->res.result(
-                boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
         const uint8_t logId = std::atoi(params[0].c_str());
@@ -583,23 +576,20 @@
                 {
                     BMCWEB_LOG_DEBUG << "failed to get log ec: "
                                      << ec.message();
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
                 const std::string *log =
                     mapbox::getPtr<const std::string>(resp);
                 if (log == nullptr)
                 {
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
                 nlohmann::json j = nlohmann::json::parse(*log, nullptr, false);
                 if (j.is_discarded())
                 {
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
                 std::string t = getLogCreatedTime(j);
@@ -652,12 +642,7 @@
         if (immediateLogMatcher != nullptr)
         {
             asyncResp->res.addHeader("Retry-After", "30");
-            asyncResp->res.result(
-                boost::beast::http::status::service_unavailable);
-            messages::addMessageToJson(
-                asyncResp->res.jsonValue,
-                messages::serviceTemporarilyUnavailable("30"),
-                "/CpuLog.Immediate");
+            messages::serviceTemporarilyUnavailable(asyncResp->res, "30");
             return;
         }
         // Make this static so it survives outside this method
@@ -678,8 +663,7 @@
             }
             BMCWEB_LOG_ERROR << "Timed out waiting for immediate log";
 
-            asyncResp->res.result(
-                boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
         });
 
         auto immediateLogMatcherCallback = [asyncResp](
@@ -702,8 +686,7 @@
                 interfacesAdded[cpuLogInterface]["Log"]);
             if (log == nullptr)
             {
-                asyncResp->res.result(
-                    boost::beast::http::status::internal_server_error);
+                messages::internalError(asyncResp->res);
                 // Careful with immediateLogMatcher.  It is a unique_ptr to the
                 // match object inside which this lambda is executing.  Once it
                 // is set to nullptr, the match object will be destroyed and the
@@ -715,8 +698,7 @@
             nlohmann::json j = nlohmann::json::parse(*log, nullptr, false);
             if (j.is_discarded())
             {
-                asyncResp->res.result(
-                    boost::beast::http::status::internal_server_error);
+                messages::internalError(asyncResp->res);
                 // Careful with immediateLogMatcher.  It is a unique_ptr to the
                 // match object inside which this lambda is executing.  Once it
                 // is set to nullptr, the match object will be destroyed and the
@@ -755,16 +737,11 @@
                     if (ec.value() ==
                         boost::system::errc::operation_not_supported)
                     {
-                        messages::addMessageToJson(
-                            asyncResp->res.jsonValue,
-                            messages::resourceInStandby(), "/CpuLog.Immediate");
-                        asyncResp->res.result(
-                            boost::beast::http::status::service_unavailable);
+                        messages::resourceInStandby(asyncResp->res);
                     }
                     else
                     {
-                        asyncResp->res.result(
-                            boost::beast::http::status::internal_server_error);
+                        messages::internalError(asyncResp->res);
                     }
                     boost::system::error_code timeoutec;
                     timeout.cancel(timeoutec);
@@ -814,20 +791,15 @@
         nlohmann::json::const_iterator caIt = rawPECICmd.find("ClientAddress");
         if (caIt == rawPECICmd.end())
         {
-            messages::addMessageToJson(
-                asyncResp->res.jsonValue,
-                messages::propertyMissing("ClientAddress"), "/ClientAddress");
-            asyncResp->res.result(boost::beast::http::status::bad_request);
+            messages::propertyMissing(asyncResp->res, "ClientAddress",
+                                      "/ClientAddress");
             return;
         }
         const uint64_t *ca = caIt->get_ptr<const uint64_t *>();
         if (ca == nullptr)
         {
-            messages::addMessageToJson(
-                asyncResp->res.jsonValue,
-                messages::propertyValueTypeError(caIt->dump(), "ClientAddress"),
-                "/ClientAddress");
-            asyncResp->res.result(boost::beast::http::status::bad_request);
+            messages::propertyValueTypeError(asyncResp->res, caIt->dump(),
+                                             "ClientAddress", "/ClientAddress");
             return;
         }
         // Get the Read Length from the request
@@ -835,20 +807,15 @@
         nlohmann::json::const_iterator rlIt = rawPECICmd.find("ReadLength");
         if (rlIt == rawPECICmd.end())
         {
-            messages::addMessageToJson(asyncResp->res.jsonValue,
-                                       messages::propertyMissing("ReadLength"),
-                                       "/ReadLength");
-            asyncResp->res.result(boost::beast::http::status::bad_request);
+            messages::propertyMissing(asyncResp->res, "ReadLength",
+                                      "/ReadLength");
             return;
         }
         const uint64_t *rl = rlIt->get_ptr<const uint64_t *>();
         if (rl == nullptr)
         {
-            messages::addMessageToJson(
-                asyncResp->res.jsonValue,
-                messages::propertyValueTypeError(rlIt->dump(), "ReadLength"),
-                "/ReadLength");
-            asyncResp->res.result(boost::beast::http::status::bad_request);
+            messages::propertyValueTypeError(asyncResp->res, rlIt->dump(),
+                                             "ReadLength", "/ReadLength");
             return;
         }
         // Get the PECI Command from the request
@@ -856,10 +823,8 @@
         nlohmann::json::const_iterator pcIt = rawPECICmd.find("PECICommand");
         if (pcIt == rawPECICmd.end())
         {
-            messages::addMessageToJson(asyncResp->res.jsonValue,
-                                       messages::propertyMissing("PECICommand"),
-                                       "/PECICommand");
-            asyncResp->res.result(boost::beast::http::status::bad_request);
+            messages::propertyMissing(asyncResp->res, "PECICommand",
+                                      "/PECICommand");
             return;
         }
         std::vector<uint8_t> peciCommand;
@@ -868,13 +833,10 @@
             const uint64_t *val = pc.get_ptr<const uint64_t *>();
             if (val == nullptr)
             {
-                messages::addMessageToJson(
-                    asyncResp->res.jsonValue,
-                    messages::propertyValueTypeError(
-                        pc.dump(),
-                        "PECICommand/" + std::to_string(peciCommand.size())),
+                messages::propertyValueTypeError(
+                    asyncResp->res, pc.dump(),
+                    "PECICommand/" + std::to_string(peciCommand.size()),
                     "/PECICommand");
-                asyncResp->res.result(boost::beast::http::status::bad_request);
                 return;
             }
             peciCommand.push_back(static_cast<uint8_t>(*val));
@@ -887,8 +849,7 @@
                 {
                     BMCWEB_LOG_DEBUG << "failed to send PECI command ec: "
                                      << ec.message();
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
                 asyncResp->res.jsonValue = {{"Name", "PECI Command Response"},
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 1fb2f69..9aa2986 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -40,9 +40,8 @@
             if (ec)
             {
                 BMCWEB_LOG_ERROR << ec;
-                asyncResp->res.result(
-                    boost::beast::http::status::internal_server_error);
                 asyncResp->res.jsonValue.clear();
+                messages::internalError(asyncResp->res);
                 return;
             }
             nlohmann::json& configRoot =
@@ -87,8 +86,7 @@
                     if (findName == intfPair.second.end())
                     {
                         BMCWEB_LOG_ERROR << "Pid Field missing Name";
-                        asyncResp->res.result(
-                            boost::beast::http::status::internal_server_error);
+                        messages::internalError(asyncResp->res, "Name");
                         return;
                     }
                     const std::string* namePtr =
@@ -138,9 +136,7 @@
                             {
                                 BMCWEB_LOG_ERROR << "Field Illegal "
                                                  << propertyPair.first;
-                                asyncResp->res.result(
-                                    boost::beast::http::status::
-                                        internal_server_error);
+                                messages::internalError(asyncResp->res);
                                 return;
                             }
                             zones[name][propertyPair.first] = *ptr;
@@ -159,9 +155,8 @@
                             if (classPtr == nullptr)
                             {
                                 BMCWEB_LOG_ERROR << "Pid Class Field illegal";
-                                asyncResp->res.result(
-                                    boost::beast::http::status::
-                                        internal_server_error);
+                                messages::internalError(asyncResp->res,
+                                                        "Class");
                                 return;
                             }
                             bool isFan = *classPtr == "fan";
@@ -204,9 +199,8 @@
                                 {
                                     BMCWEB_LOG_ERROR
                                         << "Zones Pid Field Illegal";
-                                    asyncResp->res.result(
-                                        boost::beast::http::status::
-                                            internal_server_error);
+                                    messages::internalError(asyncResp->res,
+                                                            "Zones");
                                     return;
                                 }
                                 auto& data = element[propertyPair.first];
@@ -241,9 +235,7 @@
                                 {
                                     BMCWEB_LOG_ERROR << "Field Illegal "
                                                      << propertyPair.first;
-                                    asyncResp->res.result(
-                                        boost::beast::http::status::
-                                            internal_server_error);
+                                    messages::internalError(asyncResp->res);
                                     return;
                                 }
                                 data = *inputs;
@@ -267,9 +259,7 @@
                                 {
                                     BMCWEB_LOG_ERROR << "Field Illegal "
                                                      << propertyPair.first;
-                                    asyncResp->res.result(
-                                        boost::beast::http::status::
-                                            internal_server_error);
+                                    messages::internalError(asyncResp->res);
                                     return;
                                 }
                                 element[propertyPair.first] = *ptr;
@@ -331,8 +321,7 @@
                 if (ec)
                 {
                     BMCWEB_LOG_ERROR << ec;
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
 
@@ -395,8 +384,7 @@
                 if (ec)
                 {
                     BMCWEB_LOG_ERROR << "Error while getting Software Version";
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
 
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index db47afc..f096630 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -132,10 +132,7 @@
                 if (ec)
                 {
                     asyncResp->res.jsonValue = nlohmann::json::object();
-                    messages::addMessageToErrorJson(asyncResp->res.jsonValue,
-                                                    messages::internalError());
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
 
@@ -164,10 +161,8 @@
                                     resp) {
                                 if (ec)
                                 {
-                                    messages::addMessageToJson(
-                                        asyncResp->res.jsonValue,
-                                        messages::internalError(),
-                                        "/" + service);
+                                    messages::internalError(asyncResp->res,
+                                                            "/" + service);
                                     return;
                                 }
                                 const std::vector<std::tuple<
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;
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index da05fd6..8b876a5 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -227,7 +227,8 @@
         {
             BMCWEB_LOG_INFO << "Unable to find chassis named "
                             << SensorsAsyncResp->chassisId;
-            SensorsAsyncResp->res.result(boost::beast::http::status::not_found);
+            messages::resourceNotFound(SensorsAsyncResp->res, "Chassis",
+                                       SensorsAsyncResp->chassisId);
         }
         else
         {
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 7097cfc..027c276 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -44,8 +44,7 @@
             if (ec)
             {
                 BMCWEB_LOG_DEBUG << "DBUS response error";
-                aResp->res.result(
-                    boost::beast::http::status::internal_server_error);
+                messages::internalError(aResp->res);
                 return;
             }
             bool foundName = false;
@@ -79,8 +78,7 @@
                             {
                                 BMCWEB_LOG_ERROR << "DBUS response error: "
                                                  << ec;
-                                aResp->res.result(boost::beast::http::status::
-                                                      internal_server_error);
+                                messages::internalError(aResp->res);
                                 return;
                             }
                             BMCWEB_LOG_DEBUG << "Got " << propertiesList.size()
@@ -128,9 +126,7 @@
                                         {
                                             BMCWEB_LOG_ERROR
                                                 << "DBUS response error " << ec;
-                                            aResp->res.result(
-                                                boost::beast::http::status::
-                                                    internal_server_error);
+                                            messages::internalError(aResp->res);
                                             return;
                                         }
                                         BMCWEB_LOG_DEBUG << "Got "
@@ -180,9 +176,7 @@
                                         {
                                             BMCWEB_LOG_ERROR
                                                 << "DBUS response error " << ec;
-                                            aResp->res.result(
-                                                boost::beast::http::status::
-                                                    internal_server_error);
+                                            messages::internalError(aResp->res);
                                             return;
                                         }
                                         BMCWEB_LOG_DEBUG << "Got "
@@ -238,9 +232,7 @@
                                         {
                                             BMCWEB_LOG_DEBUG
                                                 << "DBUS response error " << ec;
-                                            aResp->res.result(
-                                                boost::beast::http::status::
-                                                    internal_server_error);
+                                            messages::internalError(aResp->res);
                                             return;
                                         }
                                         BMCWEB_LOG_DEBUG << "Got "
@@ -305,8 +297,7 @@
             }
             if (foundName == false)
             {
-                aResp->res.result(
-                    boost::beast::http::status::internal_server_error);
+                messages::internalError(aResp->res);
             }
         },
         "xyz.openbmc_project.ObjectMapper",
@@ -342,8 +333,7 @@
             if (ec)
             {
                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
-                aResp->res.result(
-                    boost::beast::http::status::internal_server_error);
+                messages::internalError(aResp->res);
                 return;
             }
             BMCWEB_LOG_DEBUG << "Got " << resp.size() << "led group objects.";
@@ -394,8 +384,7 @@
             if (ec)
             {
                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
-                aResp->res.result(
-                    boost::beast::http::status::internal_server_error);
+                messages::internalError(aResp->res);
                 return;
             }
             BMCWEB_LOG_DEBUG << "Got " << properties.size()
@@ -456,8 +445,7 @@
             if (ec)
             {
                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
-                aResp->res.result(
-                    boost::beast::http::status::internal_server_error);
+                messages::internalError(aResp->res);
                 return;
             }
 
@@ -521,8 +509,7 @@
                         const std::vector<std::string> &resp) {
                 if (ec)
                 {
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
                 BMCWEB_LOG_DEBUG << "Got " << resp.size() << " boards.";
@@ -595,16 +582,13 @@
                     if (ec)
                     {
                         BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
-                        asyncResp->res.result(
-                            boost::beast::http::status::internal_server_error);
+                        messages::internalError(asyncResp->res);
                         return;
                     }
                     // TODO Consider support polling mechanism to verify
                     // status of host and chassis after execute the
                     // requested action.
-                    BMCWEB_LOG_DEBUG << "Response with no content";
-                    asyncResp->res.result(
-                        boost::beast::http::status::no_content);
+                    messages::success(asyncResp->res);
                 },
                 "xyz.openbmc_project.State.Chassis",
                 "/xyz/openbmc_project/state/chassis0",
@@ -631,10 +615,7 @@
         }
         else
         {
-            res.result(boost::beast::http::status::bad_request);
-            messages::addMessageToErrorJson(
-                asyncResp->res.jsonValue,
-                messages::actionParameterUnknown("Reset", resetType));
+            messages::actionParameterUnknown(res, "Reset", resetType);
             return;
         }
 
@@ -643,15 +624,13 @@
                 if (ec)
                 {
                     BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
                 // TODO Consider support polling mechanism to verify
                 // status of host and chassis after execute the
                 // requested action.
-                BMCWEB_LOG_DEBUG << "Response with no content";
-                asyncResp->res.result(boost::beast::http::status::no_content);
+                messages::success(asyncResp->res);
             },
             "xyz.openbmc_project.State.Host",
             "/xyz/openbmc_project/state/host0",
@@ -712,7 +691,7 @@
         // impossible
         if (params.size() != 1)
         {
-            res.result(boost::beast::http::status::internal_server_error);
+            messages::internalError(res);
             res.end();
             return;
         }
@@ -765,7 +744,7 @@
         auto asyncResp = std::make_shared<AsyncResp>(res);
         if (params.size() != 1)
         {
-            res.result(boost::beast::http::status::internal_server_error);
+            messages::internalError(asyncResp->res);
             return;
         }
 
@@ -799,9 +778,8 @@
             }
             else
             {
-                messages::addMessageToJsonRoot(
-                    res.jsonValue, messages::propertyValueNotInList(
-                                       *indicatorLed, "IndicatorLED"));
+                messages::propertyValueNotInList(
+                    res, *indicatorLed, "IndicatorLED", "IndicatorLED");
                 return;
             }
 
@@ -816,8 +794,7 @@
                     if (ec)
                     {
                         BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
-                        asyncResp->res.result(
-                            boost::beast::http::status::internal_server_error);
+                        messages::internalError(asyncResp->res);
                         return;
                     }
                     BMCWEB_LOG_DEBUG << "Led group update done.";
@@ -840,8 +817,7 @@
                     if (ec)
                     {
                         BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
-                        asyncResp->res.result(
-                            boost::beast::http::status::internal_server_error);
+                        messages::internalError(asyncResp->res);
                         return;
                     }
                     BMCWEB_LOG_DEBUG << "Led state update done.";
diff --git a/redfish-core/lib/thermal.hpp b/redfish-core/lib/thermal.hpp
index a845385..0f4e840 100644
--- a/redfish-core/lib/thermal.hpp
+++ b/redfish-core/lib/thermal.hpp
@@ -47,7 +47,7 @@
     {
         if (params.size() != 1)
         {
-            res.result(boost::beast::http::status::internal_server_error);
+            messages::internalError(res);
             res.end();
             return;
         }
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index c2f76f9..e4d5798 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -83,8 +83,7 @@
         if (fwUpdateMatcher != nullptr)
         {
             res.addHeader("Retry-After", "30");
-            res.result(boost::beast::http::status::service_unavailable);
-            res.jsonValue = messages::serviceTemporarilyUnavailable("3");
+            messages::serviceTemporarilyUnavailable(res, "3");
             res.end();
             return;
         }
@@ -111,8 +110,7 @@
                 return;
             }
 
-            res.result(boost::beast::http::status::internal_server_error);
-            res.jsonValue = redfish::messages::internalError();
+            redfish::messages::internalError(res);
             res.end();
         });
 
@@ -156,7 +154,7 @@
                         BMCWEB_LOG_ERROR << "error canceling timer " << ec;
                     }
                     UpdateService::activateImage(objPath.str); // str_objpath);
-                    res.jsonValue = redfish::messages::success();
+                    redfish::messages::success(res);
                     BMCWEB_LOG_DEBUG << "ending response";
                     res.end();
                     fwUpdateMatcher = nullptr;
@@ -222,8 +220,7 @@
                     &subtree) {
                 if (ec)
                 {
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
                 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
@@ -240,9 +237,7 @@
                     if (idPos == std::string::npos ||
                         idPos + 1 == obj.first.size())
                     {
-                        asyncResp->res.result(
-                            boost::beast::http::status::internal_server_error);
-                        asyncResp->res.jsonValue = messages::internalError();
+                        messages::internalError(asyncResp->res);
                         BMCWEB_LOG_DEBUG << "Can't parse firmware ID!!";
                         return;
                     }
@@ -264,9 +259,7 @@
                                     << "safe returned in lambda function";
                                 if (error_code)
                                 {
-                                    asyncResp->res.result(
-                                        boost::beast::http::status::
-                                            internal_server_error);
+                                    messages::internalError(asyncResp->res);
                                     return;
                                 }
 
@@ -275,9 +268,7 @@
                                         activation);
                                 if (swActivationStatus == nullptr)
                                 {
-                                    asyncResp->res.result(
-                                        boost::beast::http::status::
-                                            internal_server_error);
+                                    messages::internalError(asyncResp->res);
                                     return;
                                 }
                                 if (swActivationStatus != nullptr &&
@@ -352,8 +343,7 @@
 
         if (params.size() != 1)
         {
-            res.result(boost::beast::http::status::internal_server_error);
-            res.jsonValue = messages::internalError();
+            messages::internalError(res);
             res.end();
             return;
         }
@@ -374,8 +364,7 @@
                 BMCWEB_LOG_DEBUG << "doGet callback...";
                 if (ec)
                 {
-                    asyncResp->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(asyncResp->res);
                     return;
                 }
 
@@ -402,9 +391,7 @@
                                    std::string, VariantType> &propertiesList) {
                             if (error_code)
                             {
-                                asyncResp->res.result(
-                                    boost::beast::http::status::
-                                        internal_server_error);
+                                messages::internalError(asyncResp->res);
                                 return;
                             }
                             boost::container::flat_map<
@@ -414,9 +401,8 @@
                             {
                                 BMCWEB_LOG_DEBUG
                                     << "Can't find property \"Purpose\"!";
-                                asyncResp->res.result(
-                                    boost::beast::http::status::
-                                        internal_server_error);
+                                messages::propertyMissing(asyncResp->res,
+                                                          "Purpose");
                                 return;
                             }
                             const std::string *swInvPurpose =
@@ -425,9 +411,8 @@
                             {
                                 BMCWEB_LOG_DEBUG
                                     << "wrong types for property\"Purpose\"!";
-                                asyncResp->res.result(
-                                    boost::beast::http::status::
-                                        internal_server_error);
+                                messages::propertyValueTypeError(asyncResp->res,
+                                                                 "", "Purpose");
                                 return;
                             }
 
@@ -438,9 +423,8 @@
                             {
                                 BMCWEB_LOG_DEBUG
                                     << "Can't find property \"Version\"!";
-                                asyncResp->res.result(
-                                    boost::beast::http::status::
-                                        internal_server_error);
+                                messages::propertyMissing(asyncResp->res,
+                                                          "Version");
                                 return;
                             }
 
@@ -453,9 +437,9 @@
                             {
                                 BMCWEB_LOG_DEBUG
                                     << "Can't find property \"Version\"!";
-                                asyncResp->res.result(
-                                    boost::beast::http::status::
-                                        internal_server_error);
+
+                                messages::propertyValueTypeError(asyncResp->res,
+                                                                 "", "Version");
                                 return;
                             }
                             asyncResp->res.jsonValue["Version"] = *version;