bmcweb: merge conflict resolution

Merge conflict in: 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: I3b37cce1e7f603c0b4cc74a16f8f00da9a7f1373
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 85ef1b0..c9555a1 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -248,20 +248,17 @@
             skip = std::strtol(skipParam, &ptr, 10);
             if (*skipParam == '\0' || *ptr != '\0')
             {
-                messages::addMessageToErrorJson(
-                    asyncResp->res.jsonValue,
-                    messages::queryParameterValueTypeError(
-                        std::string(skipParam), "$skip"));
-                asyncResp->res.result(boost::beast::http::status::bad_request);
+
+                messages::queryParameterValueTypeError(
+                    asyncResp->res, std::string(skipParam), "$skip");
                 return;
             }
             if (skip < 0)
             {
-                messages::addMessageToErrorJson(
-                    asyncResp->res.jsonValue,
-                    messages::queryParameterOutOfRange(
-                        std::to_string(skip), "$skip", "greater than 0"));
-                asyncResp->res.result(boost::beast::http::status::bad_request);
+
+                messages::queryParameterOutOfRange(asyncResp->res,
+                                                   std::to_string(skip),
+                                                   "$skip", "greater than 0");
                 return;
             }
         }
@@ -272,20 +269,16 @@
             top = std::strtol(topParam, &ptr, 10);
             if (*topParam == '\0' || *ptr != '\0')
             {
-                messages::addMessageToErrorJson(
-                    asyncResp->res.jsonValue,
-                    messages::queryParameterValueTypeError(
-                        std::string(topParam), "$top"));
-                asyncResp->res.result(boost::beast::http::status::bad_request);
+                messages::queryParameterValueTypeError(
+                    asyncResp->res, std::string(topParam), "$top");
                 return;
             }
             if (top < 1 || top > maxEntriesPerPage)
             {
-                messages::addMessageToErrorJson(
-                    asyncResp->res.jsonValue,
-                    messages::queryParameterOutOfRange(
-                        std::to_string(top), "$top",
-                        "1-" + std::to_string(maxEntriesPerPage)));
+
+                messages::queryParameterOutOfRange(
+                    asyncResp->res, std::to_string(top), "$top",
+                    "1-" + std::to_string(maxEntriesPerPage));
                 asyncResp->res.result(boost::beast::http::status::bad_request);
                 return;
             }
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 12ee3b6..09a4106 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -306,8 +306,7 @@
                     {
                         BMCWEB_LOG_ERROR << "Error patching " << path << ": "
                                          << ec;
-                        response->res.result(
-                            boost::beast::http::status::internal_server_error);
+                        messages::internalError(response->res);
                     }
                 },
                 "xyz.openbmc_project.EntityManager", path,
@@ -322,12 +321,8 @@
                 if (!field.value().is_array())
                 {
                     BMCWEB_LOG_ERROR << "Illegal Type " << field.key();
-                    messages::addMessageToErrorJson(
-                        response->res.jsonValue,
-                        messages::propertyValueFormatError(field.value(),
-                                                           field.key()));
-                    response->res.result(
-                        boost::beast::http::status::bad_request);
+                    messages::propertyValueFormatError(
+                        response->res, field.value(), field.key());
                     return CreatePIDRet::fail;
                 }
                 std::vector<std::string> inputs;
@@ -340,12 +335,9 @@
                         if (path == nullptr)
                         {
                             BMCWEB_LOG_ERROR << "Illegal Type " << field.key();
-                            messages::addMessageToErrorJson(
-                                response->res.jsonValue,
-                                messages::propertyValueFormatError(
-                                    field.value().dump(), field.key()));
-                            response->res.result(
-                                boost::beast::http::status::bad_request);
+                            messages::propertyValueFormatError(
+                                response->res, field.value().dump(),
+                                field.key());
                             return CreatePIDRet::fail;
                         }
                         std::string input;
@@ -353,12 +345,9 @@
                                                                  input))
                         {
                             BMCWEB_LOG_ERROR << "Got invalid path " << *path;
-                            messages::addMessageToErrorJson(
-                                response->res.jsonValue,
-                                messages::propertyValueFormatError(
-                                    field.value().dump(), field.key()));
-                            response->res.result(
-                                boost::beast::http::status::bad_request);
+                            messages::propertyValueFormatError(
+                                response->res, field.value().dump(),
+                                field.key());
                             return CreatePIDRet::fail;
                         }
                         boost::replace_all(input, "_", " ");
@@ -372,12 +361,8 @@
                 if (!field.value().is_array())
                 {
                     BMCWEB_LOG_ERROR << "Illegal Type " << field.key();
-                    messages::addMessageToErrorJson(
-                        response->res.jsonValue,
-                        messages::propertyValueFormatError(field.value().dump(),
-                                                           field.key()));
-                    response->res.result(
-                        boost::beast::http::status::bad_request);
+                    messages::propertyValueFormatError(
+                        response->res, field.value().dump(), field.key());
                     return CreatePIDRet::fail;
                 }
                 std::vector<std::string> inputs;
@@ -390,12 +375,8 @@
                     {
                         BMCWEB_LOG_ERROR << "Illegal Type "
                                          << field.value().dump();
-                        messages::addMessageToErrorJson(
-                            response->res.jsonValue,
-                            messages::propertyValueFormatError(
-                                field.value().dump(), field.key()));
-                        response->res.result(
-                            boost::beast::http::status::bad_request);
+                        messages::propertyValueFormatError(
+                            response->res, field.value().dump(), field.key());
                         return CreatePIDRet::fail;
                     }
 
@@ -437,12 +418,8 @@
                 if (ptr == nullptr)
                 {
                     BMCWEB_LOG_ERROR << "Illegal Type " << field.key();
-                    messages::addMessageToErrorJson(
-                        response->res.jsonValue,
-                        messages::propertyValueFormatError(field.value().dump(),
-                                                           field.key()));
-                    response->res.result(
-                        boost::beast::http::status::bad_request);
+                    messages::propertyValueFormatError(
+                        response->res, field.value().dump(), field.key());
                     return CreatePIDRet::fail;
                 }
                 output[field.key()] = *ptr;
@@ -451,10 +428,7 @@
             else
             {
                 BMCWEB_LOG_ERROR << "Illegal Type " << field.key();
-                messages::addMessageToErrorJson(
-                    response->res.jsonValue,
-                    messages::propertyUnknown(field.key()));
-                response->res.result(boost::beast::http::status::bad_request);
+                messages::propertyUnknown(response->res, field.key());
                 return CreatePIDRet::fail;
             }
         }
@@ -471,8 +445,7 @@
                     {
                         BMCWEB_LOG_ERROR << "Error patching " << path << ": "
                                          << ec;
-                        response->res.result(
-                            boost::beast::http::status::internal_server_error);
+                        messages::internalError(response->res);
                     }
                 },
                 "xyz.openbmc_project.EntityManager", path,
@@ -491,22 +464,14 @@
                     if (id.key() != "@odata.id")
                     {
                         BMCWEB_LOG_ERROR << "Illegal Type " << id.key();
-                        messages::addMessageToErrorJson(
-                            response->res.jsonValue,
-                            messages::propertyUnknown(field.key()));
-                        response->res.result(
-                            boost::beast::http::status::bad_request);
+                        messages::propertyUnknown(response->res, field.key());
                         return CreatePIDRet::fail;
                     }
                     chassisId = id.value().get_ptr<const std::string*>();
                     if (chassisId == nullptr)
                     {
-                        messages::addMessageToErrorJson(
-                            response->res.jsonValue,
-                            messages::createFailedMissingReqProperties(
-                                field.key()));
-                        response->res.result(
-                            boost::beast::http::status::bad_request);
+                        messages::createFailedMissingReqProperties(
+                            response->res, field.key());
                         return CreatePIDRet::fail;
                     }
                 }
@@ -516,8 +481,7 @@
                                                          chassis))
                 {
                     BMCWEB_LOG_ERROR << "Got invalid path " << *chassisId;
-                    response->res.result(
-                        boost::beast::http::status::bad_request);
+                    messages::invalidObject(response->res, *chassisId);
                     return CreatePIDRet::fail;
                 }
             }
@@ -528,12 +492,8 @@
                 if (ptr == nullptr)
                 {
                     BMCWEB_LOG_ERROR << "Illegal Type " << field.key();
-                    messages::addMessageToErrorJson(
-                        response->res.jsonValue,
-                        messages::propertyValueFormatError(field.value().dump(),
-                                                           field.key()));
-                    response->res.result(
-                        boost::beast::http::status::bad_request);
+                    messages::propertyValueFormatError(
+                        response->res, field.value().dump(), field.key());
                     return CreatePIDRet::fail;
                 }
                 output[field.key()] = *ptr;
@@ -541,10 +501,7 @@
             else
             {
                 BMCWEB_LOG_ERROR << "Illegal Type " << field.key();
-                messages::addMessageToErrorJson(
-                    response->res.jsonValue,
-                    messages::propertyUnknown(field.key()));
-                response->res.result(boost::beast::http::status::bad_request);
+                messages::propertyUnknown(response->res, field.key());
                 return CreatePIDRet::fail;
             }
         }
@@ -552,9 +509,7 @@
     else
     {
         BMCWEB_LOG_ERROR << "Illegal Type " << type;
-        messages::addMessageToErrorJson(response->res.jsonValue,
-                                        messages::propertyUnknown(type));
-        response->res.result(boost::beast::http::status::bad_request);
+        messages::propertyUnknown(response->res, type);
         return CreatePIDRet::fail;
     }
     return CreatePIDRet::patch;
@@ -733,8 +688,7 @@
                 if (ec)
                 {
                     BMCWEB_LOG_ERROR << "Error communicating to Entity Manager";
-                    response->res.result(
-                        boost::beast::http::status::internal_server_error);
+                    messages::internalError(response->res);
                     return;
                 }
                 for (const auto& type : data.items())
@@ -742,12 +696,8 @@
                     if (!type.value().is_object())
                     {
                         BMCWEB_LOG_ERROR << "Illegal Type " << type.key();
-                        messages::addMessageToErrorJson(
-                            response->res.jsonValue,
-                            messages::propertyValueFormatError(type.value(),
-                                                               type.key()));
-                        response->res.result(
-                            boost::beast::http::status::bad_request);
+                        messages::propertyValueFormatError(
+                            response->res, type.value(), type.key());
                         return;
                     }
                     for (const auto& record : type.value().items())
@@ -819,9 +769,8 @@
                                             BMCWEB_LOG_ERROR
                                                 << "Error patching "
                                                 << propertyName << ": " << ec;
-                                            response->res.result(
-                                                boost::beast::http::status::
-                                                    internal_server_error);
+                                            messages::internalError(
+                                                response->res);
                                         }
                                     },
                                     "xyz.openbmc_project.EntityManager",
@@ -837,8 +786,7 @@
                             {
                                 BMCWEB_LOG_ERROR
                                     << "Failed to get chassis from config";
-                                response->res.result(
-                                    boost::beast::http::status::bad_request);
+                                messages::invalidObject(response->res, name);
                                 return;
                             }
 
@@ -857,13 +805,9 @@
                             {
                                 BMCWEB_LOG_ERROR
                                     << "Failed to find chassis on dbus";
-                                messages::addMessageToErrorJson(
-                                    response->res.jsonValue,
-                                    messages::resourceMissingAtURI(
-                                        "/redfish/v1/Chassis/" + chassis));
-                                response->res.result(
-                                    boost::beast::http::status::
-                                        internal_server_error);
+                                messages::resourceMissingAtURI(
+                                    response->res,
+                                    "/redfish/v1/Chassis/" + chassis);
                                 return;
                             }
 
@@ -873,9 +817,7 @@
                                     {
                                         BMCWEB_LOG_ERROR
                                             << "Error Adding Pid Object " << ec;
-                                        response->res.result(
-                                            boost::beast::http::status::
-                                                internal_server_error);
+                                        messages::internalError(response->res);
                                     }
                                 },
                                 "xyz.openbmc_project.EntityManager", chassis,
@@ -905,17 +847,15 @@
                 if (!topLevel.value().is_object())
                 {
                     BMCWEB_LOG_ERROR << "Bad Patch " << topLevel.key();
-                    res.result(boost::beast::http::status::bad_request);
+                    messages::propertyValueFormatError(
+                        response->res, topLevel.key(), "OemManager.Oem");
                     return;
                 }
             }
             else
             {
                 BMCWEB_LOG_ERROR << "Bad Patch " << topLevel.key();
-                messages::addMessageToErrorJson(
-                    response->res.jsonValue,
-                    messages::propertyUnknown(topLevel.key()));
-                res.result(boost::beast::http::status::bad_request);
+                messages::propertyUnknown(response->res, topLevel.key());
                 return;
             }
             for (const auto& oemLevel : topLevel.value().items())
@@ -925,7 +865,9 @@
                     if (!oemLevel.value().is_object())
                     {
                         BMCWEB_LOG_ERROR << "Bad Patch " << oemLevel.key();
-                        res.result(boost::beast::http::status::bad_request);
+                        messages::propertyValueFormatError(
+                            response->res, topLevel.key(),
+                            "OemManager.OpenBmc");
                         return;
                     }
                     for (const auto& typeLevel : oemLevel.value().items())
@@ -937,13 +879,9 @@
                             {
                                 BMCWEB_LOG_ERROR << "Bad Patch "
                                                  << typeLevel.key();
-                                messages::addMessageToErrorJson(
-                                    response->res.jsonValue,
-                                    messages::propertyValueFormatError(
-                                        typeLevel.value().dump(),
-                                        typeLevel.key()));
-                                res.result(
-                                    boost::beast::http::status::bad_request);
+                                messages::propertyValueFormatError(
+                                    response->res, typeLevel.value().dump(),
+                                    typeLevel.key());
                                 return;
                             }
                             setPidValues(response,
@@ -952,10 +890,8 @@
                         else
                         {
                             BMCWEB_LOG_ERROR << "Bad Patch " << typeLevel.key();
-                            messages::addMessageToErrorJson(
-                                response->res.jsonValue,
-                                messages::propertyUnknown(typeLevel.key()));
-                            res.result(boost::beast::http::status::bad_request);
+                            messages::propertyUnknown(response->res,
+                                                      typeLevel.key());
                             return;
                         }
                     }
@@ -963,10 +899,7 @@
                 else
                 {
                     BMCWEB_LOG_ERROR << "Bad Patch " << oemLevel.key();
-                    messages::addMessageToErrorJson(
-                        response->res.jsonValue,
-                        messages::propertyUnknown(oemLevel.key()));
-                    res.result(boost::beast::http::status::bad_request);
+                    messages::propertyUnknown(response->res, oemLevel.key());
                     return;
                 }
             }