summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason M. Bills <jason.m.bills@linux.intel.com>2018-10-09 22:45:45 +0300
committerJason M. Bills <jason.m.bills@linux.intel.com>2018-10-23 03:00:16 +0300
commitf12894f8bd7fc26ffa16e5a89072e6c19095f866 (patch)
treee2e2e1629f80a29efca04bd9714525465575549e
parent9712f8ac42746e65f32c2bc3de0835846652568e (diff)
downloadbmcweb-f12894f8bd7fc26ffa16e5a89072e6c19095f866.tar.xz
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>
-rw-r--r--redfish-core/include/error_messages.hpp297
-rw-r--r--redfish-core/include/node.hpp17
-rw-r--r--redfish-core/include/utils/json_utils.hpp279
-rw-r--r--redfish-core/lib/account_service.hpp73
-rw-r--r--redfish-core/lib/chassis.hpp17
-rw-r--r--redfish-core/lib/ethernet.hpp474
-rw-r--r--redfish-core/lib/log_services.hpp99
-rw-r--r--redfish-core/lib/managers.hpp34
-rw-r--r--redfish-core/lib/network_protocol.hpp11
-rw-r--r--redfish-core/lib/redfish_sessions.hpp33
-rw-r--r--redfish-core/lib/sensors.hpp3
-rw-r--r--redfish-core/lib/systems.hpp66
-rw-r--r--redfish-core/lib/thermal.hpp2
-rw-r--r--redfish-core/lib/update_service.hpp54
-rw-r--r--redfish-core/scripts/error_messages/Base.1.2.0.json516
-rw-r--r--redfish-core/scripts/error_messages/error_messages.cpp.in100
-rw-r--r--redfish-core/scripts/error_messages/error_messages.hpp.in85
-rw-r--r--redfish-core/scripts/error_messages/error_messages.py332
-rw-r--r--redfish-core/src/error_messages.cpp1586
-rw-r--r--redfish-core/src/utils/json_utils.cpp482
20 files changed, 1484 insertions, 3076 deletions
diff --git a/redfish-core/include/error_messages.hpp b/redfish-core/include/error_messages.hpp
index 085b76f6bd..62925e13d4 100644
--- a/redfish-core/include/error_messages.hpp
+++ b/redfish-core/include/error_messages.hpp
@@ -24,6 +24,8 @@
#pragma once
#include <nlohmann/json.hpp>
+#include "crow/http_response.h"
+
namespace redfish
{
@@ -34,56 +36,13 @@ constexpr const char* messageVersionPrefix = "Base.1.2.0.";
constexpr const char* messageAnnotation = "@Message.ExtendedInfo";
/**
- * @brief Adds Message JSON object to error object
- *
- * @param[out] target Target JSON to which message will be added
- * @param[in] message Message JSON that should be added to target
- *
- * @return None
- */
-void addMessageToErrorJson(nlohmann::json& target,
- const nlohmann::json& message);
-
-/**
- * @brief Adds Message JSON object to target JSON
- *
- * @internal
- * This function has similar implementation to addMessageToJson(...), but
- * does not use nlohmann::json_pointer to avoid costly construction
- * @endinternal
- *
- * @param[out] target Target JSON to which message will be added
- * @param[in] message Message JSON that should be added to target
- *
- * @return None
- */
-void addMessageToJsonRoot(nlohmann::json& target,
- const nlohmann::json& message);
-
-/**
- * @brief Adds Message JSON object connected with specific field to target JSON
- *
- * @param[out] target Target JSON to which message will be added
- * @param[in] message Message JSON that should be added to target
- * @param[in] fieldPath Path of related field
- *
- * @return None
- */
-void addMessageToJson(nlohmann::json& target, const nlohmann::json& message,
- const std::string& fieldPath);
-
-/*********************************
- * AUTOGENERATED FUNCTIONS START *
- *********************************/
-
-/**
* @brief Formats ResourceInUse message into JSON
* Message body: "The change to the requested resource failed because the
* resource is in use or in transition."
*
*
* @returns Message ResourceInUse formatted to JSON */
-nlohmann::json resourceInUse();
+void resourceInUse(crow::Response& res);
/**
* @brief Formats MalformedJSON message into JSON
@@ -92,7 +51,7 @@ nlohmann::json resourceInUse();
*
*
* @returns Message MalformedJSON formatted to JSON */
-nlohmann::json malformedJSON();
+void malformedJSON(crow::Response& res);
/**
* @brief Formats ResourceMissingAtURI message into JSON
@@ -101,7 +60,7 @@ nlohmann::json malformedJSON();
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message ResourceMissingAtURI formatted to JSON */
-nlohmann::json resourceMissingAtURI(const std::string& arg1);
+void resourceMissingAtURI(crow::Response& res, const std::string& arg1);
/**
* @brief Formats ActionParameterValueFormatError message into JSON
@@ -113,9 +72,10 @@ nlohmann::json resourceMissingAtURI(const std::string& arg1);
* @param[in] arg3 Parameter of message that will replace %3 in its body.
*
* @returns Message ActionParameterValueFormatError formatted to JSON */
-nlohmann::json actionParameterValueFormatError(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3);
+void actionParameterValueFormatError(crow::Response& res,
+ const std::string& arg1,
+ const std::string& arg2,
+ const std::string& arg3);
/**
* @brief Formats InternalError message into JSON
@@ -124,7 +84,16 @@ nlohmann::json actionParameterValueFormatError(const std::string& arg1,
*
*
* @returns Message InternalError formatted to JSON */
-nlohmann::json internalError();
+void internalError(crow::Response& res);
+
+/**
+ * @brief Formats InternalError message into JSON for the specified field
+ * Message body: "The request failed due to an internal service error. The
+ * service is still operational."
+ *
+ *
+ * @returns Message InternalError formatted to JSON */
+void internalError(crow::Response& res, const std::string& fieldPath);
/**
* @brief Formats UnrecognizedRequestBody message into JSON
@@ -133,7 +102,7 @@ nlohmann::json internalError();
*
*
* @returns Message UnrecognizedRequestBody formatted to JSON */
-nlohmann::json unrecognizedRequestBody();
+void unrecognizedRequestBody(crow::Response& res);
/**
* @brief Formats ResourceAtUriUnauthorized message into JSON
@@ -144,8 +113,8 @@ nlohmann::json unrecognizedRequestBody();
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message ResourceAtUriUnauthorized formatted to JSON */
-nlohmann::json resourceAtUriUnauthorized(const std::string& arg1,
- const std::string& arg2);
+void resourceAtUriUnauthorized(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats ActionParameterUnknown message into JSON
@@ -156,8 +125,8 @@ nlohmann::json resourceAtUriUnauthorized(const std::string& arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message ActionParameterUnknown formatted to JSON */
-nlohmann::json actionParameterUnknown(const std::string& arg1,
- const std::string& arg2);
+void actionParameterUnknown(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats ResourceCannotBeDeleted message into JSON
@@ -166,7 +135,7 @@ nlohmann::json actionParameterUnknown(const std::string& arg1,
*
*
* @returns Message ResourceCannotBeDeleted formatted to JSON */
-nlohmann::json resourceCannotBeDeleted();
+void resourceCannotBeDeleted(crow::Response& res);
/**
* @brief Formats PropertyDuplicate message into JSON
@@ -175,7 +144,7 @@ nlohmann::json resourceCannotBeDeleted();
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message PropertyDuplicate formatted to JSON */
-nlohmann::json propertyDuplicate(const std::string& arg1);
+void propertyDuplicate(crow::Response& res, const std::string& arg1);
/**
* @brief Formats ServiceTemporarilyUnavailable message into JSON
@@ -185,7 +154,8 @@ nlohmann::json propertyDuplicate(const std::string& arg1);
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message ServiceTemporarilyUnavailable formatted to JSON */
-nlohmann::json serviceTemporarilyUnavailable(const std::string& arg1);
+void serviceTemporarilyUnavailable(crow::Response& res,
+ const std::string& arg1);
/**
* @brief Formats ResourceAlreadyExists message into JSON
@@ -197,9 +167,8 @@ nlohmann::json serviceTemporarilyUnavailable(const std::string& arg1);
* @param[in] arg3 Parameter of message that will replace %3 in its body.
*
* @returns Message ResourceAlreadyExists formatted to JSON */
-nlohmann::json resourceAlreadyExists(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3);
+void resourceAlreadyExists(crow::Response& res, const std::string& arg1,
+ const std::string& arg2, const std::string& arg3);
/**
* @brief Formats AccountForSessionNoLongerExists message into JSON
@@ -208,7 +177,7 @@ nlohmann::json resourceAlreadyExists(const std::string& arg1,
*
*
* @returns Message AccountForSessionNoLongerExists formatted to JSON */
-nlohmann::json accountForSessionNoLongerExists();
+void accountForSessionNoLongerExists(crow::Response& res);
/**
* @brief Formats CreateFailedMissingReqProperties message into JSON
@@ -218,7 +187,8 @@ nlohmann::json accountForSessionNoLongerExists();
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message CreateFailedMissingReqProperties formatted to JSON */
-nlohmann::json createFailedMissingReqProperties(const std::string& arg1);
+void createFailedMissingReqProperties(crow::Response& res,
+ const std::string& arg1);
/**
* @brief Formats PropertyValueFormatError message into JSON
@@ -229,8 +199,22 @@ nlohmann::json createFailedMissingReqProperties(const std::string& arg1);
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message PropertyValueFormatError formatted to JSON */
-nlohmann::json propertyValueFormatError(const std::string& arg1,
- const std::string& arg2);
+void propertyValueFormatError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
+
+/**
+ * @brief Formats PropertyValueFormatError message into JSON for the specified
+ * property
+ * Message body: "The value <arg0> for the property <arg1> is of a different
+ * format than the property can accept."
+ *
+ * @param[in] arg1 Parameter of message that will replace %1 in its body.
+ * @param[in] arg2 Parameter of message that will replace %2 in its body.
+ *
+ * @returns Message PropertyValueFormatError formatted to JSON */
+void propertyValueFormatError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string property);
/**
* @brief Formats PropertyValueNotInList message into JSON
@@ -241,8 +225,22 @@ nlohmann::json propertyValueFormatError(const std::string& arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message PropertyValueNotInList formatted to JSON */
-nlohmann::json propertyValueNotInList(const std::string& arg1,
- const std::string& arg2);
+void propertyValueNotInList(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
+
+/**
+ * @brief Formats PropertyValueNotInList message into JSON for the specified
+ * property
+ * Message body: "The value <arg0> for the property <arg1> is not in
+ * the list of acceptable values."
+ *
+ * @param[in] arg1 Parameter of message that will replace %1 in its body.
+ * @param[in] arg2 Parameter of message that will replace %2 in its body.
+ *
+ * @returns Message PropertyValueNotInList formatted to JSON */
+void propertyValueNotInList(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string property);
/**
* @brief Formats ResourceAtUriInUnknownFormat message into JSON
@@ -252,7 +250,7 @@ nlohmann::json propertyValueNotInList(const std::string& arg1,
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message ResourceAtUriInUnknownFormat formatted to JSON */
-nlohmann::json resourceAtUriInUnknownFormat(const std::string& arg1);
+void resourceAtUriInUnknownFormat(crow::Response& res, const std::string& arg1);
/**
* @brief Formats ServiceInUnknownState message into JSON
@@ -261,7 +259,7 @@ nlohmann::json resourceAtUriInUnknownFormat(const std::string& arg1);
*
*
* @returns Message ServiceInUnknownState formatted to JSON */
-nlohmann::json serviceInUnknownState();
+void serviceInUnknownState(crow::Response& res);
/**
* @brief Formats EventSubscriptionLimitExceeded message into JSON
@@ -270,7 +268,7 @@ nlohmann::json serviceInUnknownState();
*
*
* @returns Message EventSubscriptionLimitExceeded formatted to JSON */
-nlohmann::json eventSubscriptionLimitExceeded();
+void eventSubscriptionLimitExceeded(crow::Response& res);
/**
* @brief Formats ActionParameterMissing message into JSON
@@ -281,8 +279,8 @@ nlohmann::json eventSubscriptionLimitExceeded();
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message ActionParameterMissing formatted to JSON */
-nlohmann::json actionParameterMissing(const std::string& arg1,
- const std::string& arg2);
+void actionParameterMissing(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats StringValueTooLong message into JSON
@@ -292,7 +290,8 @@ nlohmann::json actionParameterMissing(const std::string& arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message StringValueTooLong formatted to JSON */
-nlohmann::json stringValueTooLong(const std::string& arg1, const int& arg2);
+void stringValueTooLong(crow::Response& res, const std::string& arg1,
+ const int& arg2);
/**
* @brief Formats PropertyValueTypeError message into JSON
@@ -303,8 +302,22 @@ nlohmann::json stringValueTooLong(const std::string& arg1, const int& arg2);
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message PropertyValueTypeError formatted to JSON */
-nlohmann::json propertyValueTypeError(const std::string& arg1,
- const std::string& arg2);
+void propertyValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
+
+/**
+ * @brief Formats PropertyValueTypeError message into JSON for the specified
+ * property
+ * Message body: "The value <arg0> for the property <arg1> is of a
+ * different type than the property can accept."
+ *
+ * @param[in] arg1 Parameter of message that will replace %1 in its body.
+ * @param[in] arg2 Parameter of message that will replace %2 in its body.
+ *
+ * @returns Message PropertyValueTypeError formatted to JSON */
+void propertyValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string& property);
/**
* @brief Formats ResourceNotFound message into JSON
@@ -315,8 +328,8 @@ nlohmann::json propertyValueTypeError(const std::string& arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message ResourceNotFound formatted to JSON */
-nlohmann::json resourceNotFound(const std::string& arg1,
- const std::string& arg2);
+void resourceNotFound(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats CouldNotEstablishConnection message into JSON
@@ -326,7 +339,7 @@ nlohmann::json resourceNotFound(const std::string& arg1,
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message CouldNotEstablishConnection formatted to JSON */
-nlohmann::json couldNotEstablishConnection(const std::string& arg1);
+void couldNotEstablishConnection(crow::Response& res, const std::string& arg1);
/**
* @brief Formats PropertyNotWritable message into JSON
@@ -336,7 +349,19 @@ nlohmann::json couldNotEstablishConnection(const std::string& arg1);
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message PropertyNotWritable formatted to JSON */
-nlohmann::json propertyNotWritable(const std::string& arg1);
+void propertyNotWritable(crow::Response& res, const std::string& arg1);
+
+/**
+ * @brief Formats PropertyNotWritable message into JSON for the specified
+ * property
+ * Message body: "The property <arg0> is a read only property and
+ * cannot be assigned a value."
+ *
+ * @param[in] arg1 Parameter of message that will replace %1 in its body.
+ *
+ * @returns Message PropertyNotWritable formatted to JSON */
+void propertyNotWritable(crow::Response& res, const std::string& arg1,
+ const std::string& property);
/**
* @brief Formats QueryParameterValueTypeError message into JSON
@@ -347,8 +372,8 @@ nlohmann::json propertyNotWritable(const std::string& arg1);
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message QueryParameterValueTypeError formatted to JSON */
-nlohmann::json queryParameterValueTypeError(const std::string& arg1,
- const std::string& arg2);
+void queryParameterValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats ServiceShuttingDown message into JSON
@@ -357,7 +382,7 @@ nlohmann::json queryParameterValueTypeError(const std::string& arg1,
*
*
* @returns Message ServiceShuttingDown formatted to JSON */
-nlohmann::json serviceShuttingDown();
+void serviceShuttingDown(crow::Response& res);
/**
* @brief Formats ActionParameterDuplicate message into JSON
@@ -368,8 +393,8 @@ nlohmann::json serviceShuttingDown();
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message ActionParameterDuplicate formatted to JSON */
-nlohmann::json actionParameterDuplicate(const std::string& arg1,
- const std::string& arg2);
+void actionParameterDuplicate(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats ActionParameterNotSupported message into JSON
@@ -380,8 +405,8 @@ nlohmann::json actionParameterDuplicate(const std::string& arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message ActionParameterNotSupported formatted to JSON */
-nlohmann::json actionParameterNotSupported(const std::string& arg1,
- const std::string& arg2);
+void actionParameterNotSupported(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats SourceDoesNotSupportProtocol message into JSON
@@ -392,8 +417,8 @@ nlohmann::json actionParameterNotSupported(const std::string& arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message SourceDoesNotSupportProtocol formatted to JSON */
-nlohmann::json sourceDoesNotSupportProtocol(const std::string& arg1,
- const std::string& arg2);
+void sourceDoesNotSupportProtocol(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats AccountRemoved message into JSON
@@ -401,7 +426,7 @@ nlohmann::json sourceDoesNotSupportProtocol(const std::string& arg1,
*
*
* @returns Message AccountRemoved formatted to JSON */
-nlohmann::json accountRemoved();
+void accountRemoved(crow::Response& res);
/**
* @brief Formats AccessDenied message into JSON
@@ -411,7 +436,7 @@ nlohmann::json accountRemoved();
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message AccessDenied formatted to JSON */
-nlohmann::json accessDenied(const std::string& arg1);
+void accessDenied(crow::Response& res, const std::string& arg1);
/**
* @brief Formats QueryNotSupported message into JSON
@@ -419,7 +444,7 @@ nlohmann::json accessDenied(const std::string& arg1);
*
*
* @returns Message QueryNotSupported formatted to JSON */
-nlohmann::json queryNotSupported();
+void queryNotSupported(crow::Response& res);
/**
* @brief Formats CreateLimitReachedForResource message into JSON
@@ -428,7 +453,7 @@ nlohmann::json queryNotSupported();
*
*
* @returns Message CreateLimitReachedForResource formatted to JSON */
-nlohmann::json createLimitReachedForResource();
+void createLimitReachedForResource(crow::Response& res);
/**
* @brief Formats GeneralError message into JSON
@@ -437,7 +462,7 @@ nlohmann::json createLimitReachedForResource();
*
*
* @returns Message GeneralError formatted to JSON */
-nlohmann::json generalError();
+void generalError(crow::Response& res);
/**
* @brief Formats Success message into JSON
@@ -445,7 +470,15 @@ nlohmann::json generalError();
*
*
* @returns Message Success formatted to JSON */
-nlohmann::json success();
+void success(crow::Response& res);
+
+/**
+ * @brief Formats Success message into JSON for the specified field
+ * Message body: "Successfully Completed Request"
+ *
+ *
+ * @returns Message Success formatted to JSON */
+void success(crow::Response& res, const std::string& fieldPath);
/**
* @brief Formats Created message into JSON
@@ -453,7 +486,7 @@ nlohmann::json success();
*
*
* @returns Message Created formatted to JSON */
-nlohmann::json created();
+void created(crow::Response& res);
/**
* @brief Formats PropertyUnknown message into JSON
@@ -463,7 +496,18 @@ nlohmann::json created();
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message PropertyUnknown formatted to JSON */
-nlohmann::json propertyUnknown(const std::string& arg1);
+void propertyUnknown(crow::Response& res, const std::string& arg1);
+
+/**
+ * @brief Formats PropertyUnknown message into JSON for the specified property
+ * Message body: "The property <arg0> is not in the list of valid properties for
+ * the resource."
+ *
+ * @param[in] arg1 Parameter of message that will replace %1 in its body.
+ *
+ * @returns Message PropertyUnknown formatted to JSON */
+void propertyUnknown(crow::Response& res, const std::string& arg1,
+ const std::string& property);
/**
* @brief Formats NoValidSession message into JSON
@@ -472,7 +516,7 @@ nlohmann::json propertyUnknown(const std::string& arg1);
*
*
* @returns Message NoValidSession formatted to JSON */
-nlohmann::json noValidSession();
+void noValidSession(crow::Response& res);
/**
* @brief Formats InvalidObject message into JSON
@@ -481,7 +525,7 @@ nlohmann::json noValidSession();
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message InvalidObject formatted to JSON */
-nlohmann::json invalidObject(const std::string& arg1);
+void invalidObject(crow::Response& res, const std::string& arg1);
/**
* @brief Formats ResourceInStandby message into JSON
@@ -490,7 +534,7 @@ nlohmann::json invalidObject(const std::string& arg1);
*
*
* @returns Message ResourceInStandby formatted to JSON */
-nlohmann::json resourceInStandby();
+void resourceInStandby(crow::Response& res);
/**
* @brief Formats ActionParameterValueTypeError message into JSON
@@ -502,9 +546,9 @@ nlohmann::json resourceInStandby();
* @param[in] arg3 Parameter of message that will replace %3 in its body.
*
* @returns Message ActionParameterValueTypeError formatted to JSON */
-nlohmann::json actionParameterValueTypeError(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3);
+void actionParameterValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string& arg3);
/**
* @brief Formats SessionLimitExceeded message into JSON
@@ -513,7 +557,7 @@ nlohmann::json actionParameterValueTypeError(const std::string& arg1,
*
*
* @returns Message SessionLimitExceeded formatted to JSON */
-nlohmann::json sessionLimitExceeded();
+void sessionLimitExceeded(crow::Response& res);
/**
* @brief Formats ActionNotSupported message into JSON
@@ -522,7 +566,7 @@ nlohmann::json sessionLimitExceeded();
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message ActionNotSupported formatted to JSON */
-nlohmann::json actionNotSupported(const std::string& arg1);
+void actionNotSupported(crow::Response& res, const std::string& arg1);
/**
* @brief Formats InvalidIndex message into JSON
@@ -531,7 +575,7 @@ nlohmann::json actionNotSupported(const std::string& arg1);
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message InvalidIndex formatted to JSON */
-nlohmann::json invalidIndex(const int& arg1);
+void invalidIndex(crow::Response& res, const int& arg1);
/**
* @brief Formats EmptyJSON message into JSON
@@ -540,7 +584,7 @@ nlohmann::json invalidIndex(const int& arg1);
*
*
* @returns Message EmptyJSON formatted to JSON */
-nlohmann::json emptyJSON();
+void emptyJSON(crow::Response& res);
/**
* @brief Formats QueryNotSupportedOnResource message into JSON
@@ -548,7 +592,7 @@ nlohmann::json emptyJSON();
*
*
* @returns Message QueryNotSupportedOnResource formatted to JSON */
-nlohmann::json queryNotSupportedOnResource();
+void queryNotSupportedOnResource(crow::Response& res);
/**
* @brief Formats InsufficientPrivilege message into JSON
@@ -558,7 +602,7 @@ nlohmann::json queryNotSupportedOnResource();
*
*
* @returns Message InsufficientPrivilege formatted to JSON */
-nlohmann::json insufficientPrivilege();
+void insufficientPrivilege(crow::Response& res);
/**
* @brief Formats PropertyValueModified message into JSON
@@ -569,8 +613,8 @@ nlohmann::json insufficientPrivilege();
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message PropertyValueModified formatted to JSON */
-nlohmann::json propertyValueModified(const std::string& arg1,
- const std::string& arg2);
+void propertyValueModified(crow::Response& res, const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats AccountNotModified message into JSON
@@ -578,7 +622,7 @@ nlohmann::json propertyValueModified(const std::string& arg1,
*
*
* @returns Message AccountNotModified formatted to JSON */
-nlohmann::json accountNotModified();
+void accountNotModified(crow::Response& res);
/**
* @brief Formats QueryParameterValueFormatError message into JSON
@@ -589,8 +633,9 @@ nlohmann::json accountNotModified();
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message QueryParameterValueFormatError formatted to JSON */
-nlohmann::json queryParameterValueFormatError(const std::string& arg1,
- const std::string& arg2);
+void queryParameterValueFormatError(crow::Response& res,
+ const std::string& arg1,
+ const std::string& arg2);
/**
* @brief Formats PropertyMissing message into JSON
@@ -600,7 +645,18 @@ nlohmann::json queryParameterValueFormatError(const std::string& arg1,
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message PropertyMissing formatted to JSON */
-nlohmann::json propertyMissing(const std::string& arg1);
+void propertyMissing(crow::Response& res, const std::string& arg1);
+
+/**
+ * @brief Formats PropertyMissing message into JSON for the specified property
+ * Message body: "The property <arg0> is a required property and must be
+ * included in the request."
+ *
+ * @param[in] arg1 Parameter of message that will replace %1 in its body.
+ *
+ * @returns Message PropertyMissing formatted to JSON */
+void propertyMissing(crow::Response& res, const std::string& arg1,
+ const std::string& property);
/**
* @brief Formats ResourceExhaustion message into JSON
@@ -610,7 +666,7 @@ nlohmann::json propertyMissing(const std::string& arg1);
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message ResourceExhaustion formatted to JSON */
-nlohmann::json resourceExhaustion(const std::string& arg1);
+void resourceExhaustion(crow::Response& res, const std::string& arg1);
/**
* @brief Formats AccountModified message into JSON
@@ -618,7 +674,7 @@ nlohmann::json resourceExhaustion(const std::string& arg1);
*
*
* @returns Message AccountModified formatted to JSON */
-nlohmann::json accountModified();
+void accountModified(crow::Response& res, const std::string& fieldPath);
/**
* @brief Formats QueryParameterOutOfRange message into JSON
@@ -630,13 +686,8 @@ nlohmann::json accountModified();
* @param[in] arg3 Parameter of message that will replace %3 in its body.
*
* @returns Message QueryParameterOutOfRange formatted to JSON */
-nlohmann::json queryParameterOutOfRange(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3);
-
-/*********************************
- * AUTOGENERATED FUNCTIONS END *
- *********************************/
+void queryParameterOutOfRange(crow::Response& res, const std::string& arg1,
+ const std::string& arg2, const std::string& arg3);
} // namespace messages
diff --git a/redfish-core/include/node.hpp b/redfish-core/include/node.hpp
index 80e0744f3c..41257e0451 100644
--- a/redfish-core/include/node.hpp
+++ b/redfish-core/include/node.hpp
@@ -39,23 +39,6 @@ class AsyncResp
~AsyncResp()
{
- if (res.result() != boost::beast::http::status::ok)
- {
- nlohmann::json::iterator error = res.jsonValue.find("error");
-
- if (error == res.jsonValue.end())
- {
- // If an error value hasn't yet been set, assume that whatever
- // content we have is garbage, and provide a worthless internal
- // server error
- res.jsonValue = {};
- }
- // Reset the json object to clear out any data that made it in
- // before the error happened todo(ed) handle error condition with
- // proper code
- messages::addMessageToErrorJson(res.jsonValue,
- messages::internalError());
- }
res.end();
}
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp
index 3263c739a8..b8195c4cb6 100644
--- a/redfish-core/include/utils/json_utils.hpp
+++ b/redfish-core/include/utils/json_utils.hpp
@@ -28,264 +28,6 @@ namespace json_util
{
/**
- * @brief Defines JSON utils operation status
- */
-enum class Result
-{
- SUCCESS,
- NOT_EXIST,
- WRONG_TYPE,
- NULL_POINTER
-};
-
-/**
- * @brief Describes JSON utils messages requirement
- */
-enum class MessageSetting
-{
- NONE = 0x0, ///< No messages will be added
- MISSING = 0x1, ///< PropertyMissing message will be added
- TYPE_ERROR = 0x2 ///< PropertyValueTypeError message will be added
-};
-
-/**
- * @brief Wrapper function for extracting string from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getString(const char* fieldName, const nlohmann::json& json,
- const std::string*& output);
-
-/**
- * @brief Wrapper function for extracting object from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getObject(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output);
-
-/**
- * @brief Wrapper function for extracting array from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getArray(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output);
-
-/**
- * @brief Wrapper function for extracting int from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getInt(const char* fieldName, const nlohmann::json& json,
- int64_t& output);
-
-/**
- * @brief Wrapper function for extracting uint from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getUnsigned(const char* fieldName, const nlohmann::json& json,
- uint64_t& output);
-
-/**
- * @brief Wrapper function for extracting bool from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getBool(const char* fieldName, const nlohmann::json& json, bool& output);
-
-/**
- * @brief Wrapper function for extracting float from JSON object without
- * throwing exceptions (nlohmann stores JSON floats as C++ doubles)
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getDouble(const char* fieldName, const nlohmann::json& json,
- double& output);
-
-/**
- * @brief Wrapper function for extracting string from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- * @param[in] msgCfgMap Map for message addition settings
- * @param[out] msgJson JSON to which error messages will be added
- * @param[in] fieldPath Field path in JSON
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getString(const char* fieldName, const nlohmann::json& json,
- const std::string*& output, uint8_t msgCfgMap,
- nlohmann::json& msgJson, const std::string&& fieldPath);
-
-/**
- * @brief Wrapper function for extracting object from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- * @param[in] msgCfgMap Map for message addition settings
- * @param[out] msgJson JSON to which error messages will be added
- * @param[in] fieldPath Field path in JSON
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getObject(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output, uint8_t msgCfgMap,
- nlohmann::json& msgJson, const std::string&& fieldPath);
-
-/**
- * @brief Wrapper function for extracting array from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- * @param[in] msgCfgMap Map for message addition settings
- * @param[out] msgJson JSON to which error messages will be added
- * @param[in] fieldPath Field path in JSON
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getArray(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output, uint8_t msgCfgMap,
- nlohmann::json& msgJson, const std::string&& fieldPath);
-
-/**
- * @brief Wrapper function for extracting int from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- * @param[in] msgCfgMap Map for message addition settings
- * @param[out] msgJson JSON to which error messages will be added
- * @param[in] fieldPath Field path in JSON
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getInt(const char* fieldName, const nlohmann::json& json,
- int64_t& output, uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath);
-
-/**
- * @brief Wrapper function for extracting uint from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- * @param[in] msgCfgMap Map for message addition settings
- * @param[out] msgJson JSON to which error messages will be added
- * @param[in] fieldPath Field path in JSON
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getUnsigned(const char* fieldName, const nlohmann::json& json,
- uint64_t& output, uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath);
-
-/**
- * @brief Wrapper function for extracting bool from JSON object without
- * throwing exceptions
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- * @param[in] msgCfgMap Map for message addition settings
- * @param[out] msgJson JSON to which error messages will be added
- * @param[in] fieldPath Field path in JSON
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getBool(const char* fieldName, const nlohmann::json& json, bool& output,
- uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath);
-
-/**
- * @brief Wrapper function for extracting float from JSON object without
- * throwing exceptions (nlohmann stores JSON floats as C++ doubles)
- *
- * @param[in] fieldName Name of requested field
- * @param[in] json JSON object from which field should be extracted
- * @param[out] output Variable to which extracted will be written in case
- * of success
- * @param[in] msgCfgMap Map for message addition settings
- * @param[out] msgJson JSON to which error messages will be added
- * @param[in] fieldPath Field path in JSON
- *
- * @return Result informing about operation status, output will be
- * written only in case of Result::SUCCESS
- */
-Result getDouble(const char* fieldName, const nlohmann::json& json,
- double& output, uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath);
-
-/**
* @brief Processes request to extract JSON from its body. If it fails, adds
* MalformedJSON message to response and ends it.
*
@@ -318,9 +60,7 @@ void readJsonValues(const std::string& key, nlohmann::json& jsonValue,
crow::Response& res, std::bitset<Count>& handled)
{
BMCWEB_LOG_DEBUG << "Unable to find variable for key" << key;
- messages::addMessageToErrorJson(res.jsonValue,
- messages::propertyUnknown(key));
- res.result(boost::beast::http::status::bad_request);
+ messages::propertyUnknown(res, key, key);
}
template <size_t Count, size_t Index, typename ValueType,
@@ -344,11 +84,7 @@ void readJsonValues(const std::string& key, nlohmann::json& jsonValue,
{
BMCWEB_LOG_DEBUG << "Value for key " << key
<< " was incorrect type: " << jsonValue.type_name();
- messages::addMessageToErrorJson(
- res.jsonValue,
- messages::propertyValueTypeError(jsonValue.dump(), key));
- res.result(boost::beast::http::status::bad_request);
-
+ messages::propertyValueTypeError(res, jsonValue.dump(), key, key);
return;
}
@@ -367,9 +103,7 @@ void handleMissing(std::bitset<Count>& handled, crow::Response& res,
{
if (!handled.test(Index) && unpackValue<ValueType>::isRequired::value)
{
- messages::addMessageToErrorJson(res.jsonValue,
- messages::propertyMissing(key));
- res.result(boost::beast::http::status::bad_request);
+ messages::propertyMissing(res, key, key);
}
details::handleMissing<Index + 1, Count>(handled, res, in...);
}
@@ -388,17 +122,14 @@ bool readJson(const crow::Request& req, crow::Response& res, const char* key,
if (!jsonRequest.is_object())
{
BMCWEB_LOG_DEBUG << "Json value is not an object";
- messages::addMessageToErrorJson(res.jsonValue,
- messages::unrecognizedRequestBody());
- res.result(boost::beast::http::status::bad_request);
+ messages::unrecognizedRequestBody(res);
return false;
}
if (jsonRequest.empty())
{
BMCWEB_LOG_DEBUG << "Json value is empty";
- messages::addMessageToErrorJson(res.jsonValue, messages::emptyJSON());
- res.result(boost::beast::http::status::bad_request);
+ messages::emptyJSON(res);
return false;
}
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index cc375914ec..4e5d676e9a 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -103,8 +103,7 @@ class AccountsCollection : public Node
const ManagedObjectType& users) {
if (ec)
{
- asyncResp->res.result(
- boost::beast::http::status::internal_server_error);
+ messages::internalError(asyncResp->res);
return;
}
@@ -153,10 +152,7 @@ class AccountsCollection : public Node
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 @@ class AccountsCollection : public Node
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 @@ class AccountsCollection : public Node
[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 @@ class AccountsCollection : public Node
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 @@ class ManagerAccount : public Node
if (params.size() != 1)
{
- res.result(boost::beast::http::status::internal_server_error);
+ messages::internalError(asyncResp->res);
return;
}
@@ -301,8 +289,7 @@ class ManagerAccount : public Node
const ManagedObjectType& users) {
if (ec)
{
- asyncResp->res.result(
- boost::beast::http::status::internal_server_error);
+ messages::internalError(asyncResp->res);
return;
}
@@ -371,7 +358,8 @@ class ManagerAccount : public Node
}
}
- 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 @@ class ManagerAccount : public Node
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 @@ class ManagerAccount : public Node
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 @@ class ManagerAccount : public Node
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 @@ class ManagerAccount : public Node
{
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 @@ class ManagerAccount : public Node
if (params.size() != 1)
{
- res.result(boost::beast::http::status::internal_server_error);
+ messages::internalError(asyncResp->res);
return;
}
@@ -471,17 +450,13 @@ class ManagerAccount : public Node
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 fa10d5c6ec..6615760834 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -80,10 +80,7 @@ class ChassisCollection : public Node
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 @@ class Chassis : public Node
// impossible.
if (params.size() != 1)
{
- res.result(boost::beast::http::status::internal_server_error);
+ messages::internalError(res);
res.end();
return;
}
@@ -165,10 +162,7 @@ class Chassis : public Node
&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 @@ class Chassis : public Node
}
// 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 da4df20df5..7da7d0a112 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -480,9 +480,9 @@ inline void changeIPv4AddressProperty(
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 @@ inline void changeIPv4Origin(const std::string &ifaceId, int ipIdx,
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 @@ inline void changeIPv4SubnetMaskProperty(const std::string &ifaceId, int ipIdx,
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 @@ inline void deleteIPv4(const std::string &ifaceId, const std::string &ipHash,
[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 @@ inline void createIPv4(const std::string &ifaceId, unsigned int 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) +
+ "/");
}
};
@@ -805,31 +805,31 @@ class EthernetCollection : public Node
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);
- res.end();
- return;
- }
+ 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}});
- }
+ 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();
- });
+ res.jsonValue["Members@odata.count"] = iface_array.size();
+ res.jsonValue["@odata.id"] =
+ "/redfish/v1/Managers/bmc/EthernetInterfaces";
+ res.end();
+ });
}
};
@@ -871,45 +871,37 @@ class EthernetInterface : public Node
{
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 @@ class EthernetInterface : public Node
{
// 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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
{
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 @@ class EthernetInterface : public Node
{
// 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 @@ class EthernetInterface : public Node
// 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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
{
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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
*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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
// 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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
{
// 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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
// ... 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 @@ class EthernetInterface : public Node
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 @@ class EthernetInterface : public Node
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 @@ class VlanNetworkInterface : public Node
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 @@ class VlanNetworkInterface : public Node
// impossible.
if (params.size() != 2)
{
- res.result(boost::beast::http::status::internal_server_error);
+ messages::internalError(res);
res.end();
return;
}
@@ -1605,12 +1545,8 @@ class VlanNetworkInterface : public Node
// ... 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 @@ class VlanNetworkInterface : public Node
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 @@ class VlanNetworkInterface : public Node
{
// 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 @@ class VlanNetworkInterface : public Node
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 @@ class VlanNetworkInterface : public Node
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 @@ class VlanNetworkInterface : public Node
// 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 @@ class VlanNetworkInterfaceCollection : public Node
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 @@ class VlanNetworkInterfaceCollection : public Node
// 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;
+ getEthernetIfaceList(
+ [this, asyncResp,
+ rootInterfaceName{std::string(rootInterfaceName)}](
+ const bool &success,
+ const std::vector<std::string> &iface_list) {
+ if (!success)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ asyncResp->res.jsonValue = Node::json;
- nlohmann::json iface_array = nlohmann::json::array();
+ nlohmann::json iface_array = nlohmann::json::array();
- for (const std::string &iface_item : iface_list)
- {
- if (boost::starts_with(iface_item, rootInterfaceName + "_"))
+ for (const std::string &iface_item : iface_list)
{
- iface_array.push_back(
- {{"@odata.id",
- "/redfish/v1/Managers/bmc/EthernetInterfaces/" +
- rootInterfaceName + "/VLANs/" + iface_item}});
+ 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::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";
- });
+ 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 @@ class VlanNetworkInterfaceCollection : public Node
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 @@ class VlanNetworkInterfaceCollection : public Node
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 @@ class VlanNetworkInterfaceCollection : public Node
{
// 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 ee342cfbb9..562bbfcc93 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -260,8 +260,7 @@ class BMCLogEntryCollection : public Node
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 @@ class BMCLogEntryCollection : public Node
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 @@ class BMCLogEntry : public Node
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 @@ class BMCLogEntry : public Node
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 @@ class BMCLogEntry : public Node
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 @@ class CPULogEntryCollection : public Node
{
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 @@ class CPULogEntry : public Node
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 @@ class CPULogEntry : public Node
{
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 @@ class ImmediateCPULog : public Node
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 @@ class ImmediateCPULog : public Node
}
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 @@ class ImmediateCPULog : public Node
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 @@ class ImmediateCPULog : public Node
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 @@ class ImmediateCPULog : public Node
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 @@ class SendRawPECI : public Node
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 @@ class SendRawPECI : public Node
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 @@ class SendRawPECI : public Node
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 @@ class SendRawPECI : public Node
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 @@ class SendRawPECI : public Node
{
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 1fb2f69758..9aa29864a4 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -40,9 +40,8 @@ static void asyncPopulatePid(const std::string& connection,
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 @@ static void asyncPopulatePid(const std::string& connection,
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 @@ static void asyncPopulatePid(const std::string& connection,
{
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 @@ static void asyncPopulatePid(const std::string& connection,
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 @@ static void asyncPopulatePid(const std::string& connection,
{
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 @@ static void asyncPopulatePid(const std::string& connection,
{
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 @@ static void asyncPopulatePid(const std::string& connection,
{
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 @@ class Manager : public Node
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 @@ class Manager : public Node
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 db47afce0b..f096630201 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -132,10 +132,7 @@ class NetworkProtocol : public Node
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 @@ class NetworkProtocol : public Node
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 4922724516..b0a294878d 100644
--- a/redfish-core/lib/redfish_sessions.hpp
+++ b/redfish-core/lib/redfish_sessions.hpp
@@ -54,11 +54,7 @@ class Sessions : public Node
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 @@ class Sessions : public Node
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 @@ class Sessions : public Node
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 @@ class SessionCollection : public Node
{
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 @@ class SessionCollection : public Node
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 da05fd67ee..8b876a5b43 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -227,7 +227,8 @@ void getChassis(std::shared_ptr<SensorsAsyncResp> SensorsAsyncResp,
{
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 7097cfcac6..027c2762c7 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -44,8 +44,7 @@ void getComputerSystem(std::shared_ptr<AsyncResp> aResp,
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 @@ void getComputerSystem(std::shared_ptr<AsyncResp> aResp,
{
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 @@ void getComputerSystem(std::shared_ptr<AsyncResp> aResp,
{
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 @@ void getComputerSystem(std::shared_ptr<AsyncResp> aResp,
{
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 @@ void getComputerSystem(std::shared_ptr<AsyncResp> aResp,
{
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 @@ void getComputerSystem(std::shared_ptr<AsyncResp> aResp,
}
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 @@ void getLedGroupIdentify(std::shared_ptr<AsyncResp> aResp,
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 @@ void getLedIdentify(std::shared_ptr<AsyncResp> aResp, CallbackFunc &&callback)
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 @@ void getHostState(std::shared_ptr<AsyncResp> aResp)
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 @@ class SystemsCollection : public Node
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 @@ class SystemActionsReset : public Node
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 @@ class SystemActionsReset : public Node
}
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 @@ class SystemActionsReset : public Node
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 @@ class Systems : public Node
// impossible
if (params.size() != 1)
{
- res.result(boost::beast::http::status::internal_server_error);
+ messages::internalError(res);
res.end();
return;
}
@@ -765,7 +744,7 @@ class Systems : public Node
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 @@ class Systems : public Node
}
else
{
- messages::addMessageToJsonRoot(
- res.jsonValue, messages::propertyValueNotInList(
- *indicatorLed, "IndicatorLED"));
+ messages::propertyValueNotInList(
+ res, *indicatorLed, "IndicatorLED", "IndicatorLED");
return;
}
@@ -816,8 +794,7 @@ class Systems : public Node
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 @@ class Systems : public Node
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 a8453857e5..0f4e840a97 100644
--- a/redfish-core/lib/thermal.hpp
+++ b/redfish-core/lib/thermal.hpp
@@ -47,7 +47,7 @@ class Thermal : public Node
{
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 c2f76f9426..e4d5798961 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -83,8 +83,7 @@ class UpdateService : public Node
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 @@ class UpdateService : public Node
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 @@ class UpdateService : public Node
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 @@ class SoftwareInventoryCollection : public Node
&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 @@ class SoftwareInventoryCollection : public Node
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 @@ class SoftwareInventoryCollection : public Node
<< "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 @@ class SoftwareInventoryCollection : public Node
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 @@ class SoftwareInventory : public Node
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 @@ class SoftwareInventory : public Node
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 @@ class SoftwareInventory : public Node
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 @@ class SoftwareInventory : public Node
{
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 @@ class SoftwareInventory : public Node
{
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 @@ class SoftwareInventory : public Node
{
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 @@ class SoftwareInventory : public Node
{
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;
diff --git a/redfish-core/scripts/error_messages/Base.1.2.0.json b/redfish-core/scripts/error_messages/Base.1.2.0.json
deleted file mode 100644
index 3c8c1bbf36..0000000000
--- a/redfish-core/scripts/error_messages/Base.1.2.0.json
+++ /dev/null
@@ -1,516 +0,0 @@
-{
- "@Redfish.Copyright": "Copyright 2014-2015, 2017 Distributed Management Task Force, Inc. (DMTF). All rights reserved.",
- "@odata.type": "#MessageRegistry.v1_0_0.MessageRegistry",
- "Id": "Base.1.2.0",
- "Name": "Base Message Registry",
- "Language": "en",
- "Description": "This registry defines the base messages for Redfish",
- "RegistryPrefix": "Base",
- "RegistryVersion": "1.2.0",
- "OwningEntity": "DMTF",
- "Messages": {
- "Success": {
- "Description": "Indicates that all conditions of a successful operation have been met.",
- "Message": "Successfully Completed Request",
- "Severity": "OK",
- "NumberOfArgs": 0,
- "Resolution": "None"
- },
- "GeneralError": {
- "Description": "Indicates that a general error has occurred.",
- "Message": "A general error has occurred. See ExtendedInfo for more information.",
- "Severity": "Critical",
- "NumberOfArgs": 0,
- "Resolution": "See ExtendedInfo for more information."
- },
- "Created": {
- "Description": "Indicates that all conditions of a successful creation operation have been met.",
- "Message": "The resource has been created successfully",
- "Severity": "OK",
- "NumberOfArgs": 0,
- "Resolution": "None"
- },
- "PropertyDuplicate": {
- "Description": "Indicates that a duplicate property was included in the request body.",
- "Message": "The property %1 was duplicated in the request.",
- "Severity": "Warning",
- "NumberOfArgs": 1,
- "ParamTypes": [
- "string"
- ],
- "Resolution": "Remove the duplicate property from the request body and resubmit the request if the operation failed."
- },
- "PropertyUnknown": {
- "Description": "Indicates that an unknown property was included in the request body.",
- "Message": "The property %1 is not in the list of valid properties for the resource.",
- "Severity": "Warning",
- "NumberOfArgs": 1,
- "ParamTypes": [
- "string"
- ],
- "Resolution": "Remove the unknown property from the request body and resubmit the request if the operation failed."
- },
- "PropertyValueTypeError": {
- "Description": "Indicates that a property was given the wrong value type, such as when a number is supplied for a property that requires a string.",
- "Message": "The value %1 for the property %2 is of a different type than the property can accept.",
- "Severity": "Warning",
- "NumberOfArgs": 2,
- "ParamTypes": [
- "string",
- "string"
- ],
- "Resolution": "Correct the value for the property in the request body and resubmit the request if the operation failed."
- },
- "PropertyValueFormatError": {
- "Description": "Indicates that a property was given the correct value type but the value of that property was not supported.",
- "Message": "The value %1 for the property %2 is of a different format than the property can accept.",
- "Severity": "Warning",
- "NumberOfArgs": 2,
- "ParamTypes": [
- "string",
- "string"
- ],
- "Resolution": "Correct the value for the property in the request body and resubmit the request if the operation failed."
- },
- "PropertyValueNotInList": {
- "Description": "Indicates that a property was given the correct value type but the value of that property was not supported. This values not in an enumeration",
- "Message": "The value %1 for the property %2 is not in the list of acceptable values.",
- "Severity": "Warning",
- "NumberOfArgs": 2,
- "ParamTypes": [
- "string",
- "string"
- ],
- "Resolution": "Choose a value from the enumeration list that the implementation can support and resubmit the request if the operation failed."
- },
- "PropertyNotWritable": {
- "Description": "Indicates that a property was given a value in the request body, but the property is a readonly property.",
- "Message": "The property %1 is a read only property and cannot be assigned a value.",
- "Severity": "Warning",
- "NumberOfArgs": 1,
- "ParamTypes": [
- "string"
- ],
- "Resolution": "Remove the property from the request body and resubmit the request if the operation failed."
- },
- "PropertyMissing": {
- "Description": "Indicates that a required property was not supplied as part of the request.",
- "Message": "The property %1 is a required property and must be included in the request.",
- "Severity": "Warning",
- "NumberOfArgs": 1,
- "ParamTypes": [
- "string"
- ],
- "Resolution": "Ensure that the property is in the request body and has a valid value and resubmit the request if the operation failed."
- },
- "MalformedJSON": {
- "Description": "Indicates that the request body was malformed JSON. Could be duplicate, syntax error,etc.",
- "Message": "The request body submitted was malformed JSON and could not be parsed by the receiving service.",
- "Severity": "Critical",
- "NumberOfArgs": 0,
- "Resolution": "Ensure that the request body is valid JSON and resubmit the request."
- },
- "EmptyJSON": {
- "Description": "Indicates that the request body contained an empty JSON object when one or more properties are expected in the body.",
- "Message": "The request body submitted contained an empty JSON object and the service is unable to process it.",
- "Severity": "Warning",
- "NumberOfArgs": 0,
- "Resolution": "Add properties in the JSON object and resubmit the request."
- },
- "ActionNotSupported": {
- "Description": "Indicates that the action supplied with the POST operation is not supported by the resource.",
- "Message": "The action %1 is not supported by the resource.",
- "Severity": "Critical",
- "NumberOfArgs": 1,
- "ParamTypes": [
- "string"
- ],
- "Resolution": "The action supplied cannot be resubmitted to the implementation. Perhaps the action was invalid, the wrong resource was the target or the implementation documentation may be of assistance."
- },
- "ActionParameterMissing": {
- "Description": "Indicates that the action requested was missing a parameter that is required to process the action.",
- "Message": "The action %1 requires the parameter %2 to be present in the request body.",
- "Severity": "Critical",
- "NumberOfArgs": 2,
- "ParamTypes": [
- "string",
- "string"
- ],
- "Resolution": "Supply the action with the required parameter in the request body when the request is resubmitted."
- },
- "ActionParameterDuplicate": {
- "Description": "Indicates that the action was supplied with a duplicated parameter in the request body.",
- "Message": "The action %1 was submitted with more than one value for the parameter %2.",
- "Severity": "Warning",
- "NumberOfArgs": 2,
- "ParamTypes": [
- "string",
- "string"
- ],
- "Resolution": "Resubmit the action with only one instance of the parameter in the request body if the operation failed."
- },
- "ActionParameterUnknown": {
- "Description": "Indicates that an action was submitted but a parameter supplied did not match any of the known parameters.",
- "Message": "The action %1 was submitted with the invalid parameter %2.",
- "Severity": "Warning",
- "NumberOfArgs": 2,
- "ParamTypes": [
- "string",
- "string"
- ],
- "Resolution": "Correct the invalid parameter and resubmit the request if the operation failed."
- },
- "ActionParameterValueTypeError": {
- "Description": "Indicates that a parameter was given the wrong value type, such as when a number is supplied for a parameter that requires a string.",
- "Message": "The value %1 for the parameter %2 in the action %3 is of a different type than the parameter can accept.",
- "Severity": "Warning",
- "NumberOfArgs": 3,
- "ParamTypes": [
- "string",
- "string",
- "string"
- ],
- "Resolution": "Correct the value for the parameter in the request body and resubmit the request if the operation failed."
- },
- "ActionParameterValueFormatError": {
- "Description": "Indicates that a parameter was given the correct value type but the value of that parameter was not supported. This includes value size/length exceeded.",
- "Message": "The value %1 for the parameter %2 in the action %3 is of a different format than the parameter can accept.",
- "Severity": "Warning",
- "NumberOfArgs": 3,
- "ParamTypes": [
- "string",
- "string",
- "string"
- ],
- "Resolution": "Correct the value for the parameter in the request body and resubmit the request if the operation failed."
- },
- "ActionParameterNotSupported": {
- "Description": "Indicates that the parameter supplied for the action is not supported on the resource.",
- "Message": "The parameter %1 for the action %2 is not supported on the target resource.",
- "Severity": "Warning",
- "NumberOfArgs": 2,
- "ParamTypes": [
- "string",
- "string"
- ],
- "Resolution": "Remove the parameter supplied and resubmit the request if the operation failed."
- },
- "QueryParameterValueTypeError": {
- "Description": "Indicates that a query parameter was given the wrong value type, such as when a number is supplied for a query parameter that requires a string.",
- "Message": "The value %1 for the query parameter %2 is of a different type than the parameter can accept.",
- "Severity": "Warning",
- "NumberOfArgs": 2,
- "ParamTypes": [
- "string",
- "string"
- ],
- "Resolution": "Correct the value for the query parameter in the request and resubmit the request if the operation failed."
- },
- "QueryParameterValueFormatError": {
- "Description": "Indicates that a query parameter was given the correct value type but the value of that parameter was not supported. This includes value size/length exceeded.",
- "Message": "The value %1 for the parameter %2 is of a different format than the parameter can accept.",
- "Severity": "Warning",
- "NumberOfArgs": 2,
- "ParamTypes": [
- "string",
- "string"
- ],
- "Resolution": "Correct the value for the query parameter in the request and resubmit the request if the operation failed."
- },
- "QueryParameterOutOfRange": {
- "Description": "Indicates that a query parameter was supplied that is out of range for the given resource. This can happen with values that are too low or beyond that possible for the supplied resource, such as when a page is requested that is beyond the last page.",
- "Message": "The value %1 for the query parameter %2 is out of range %3.",
- "Severity": "Warning",
- "NumberOfArgs": 3,
- "ParamTypes": [
- "string",
- "string",
- "string"
- ],
- "Resolution": "Reduce the value for the query parameter to a value that is within range, such as a start or count value that is within bounds of the number of resources in a collection or a page that is within the range of valid pages."
- },
- "QueryNotSupportedOnResource": {
- "Description": "Indicates that query is not supported on the given resource, such as when a start/count query is attempted on a resource that is not a collection.",
- "Message": "Querying is not supported on the requested resource.",
- "Severity": "Warning",
- "NumberOfArgs": 0,
- "Resolution": "Remove the query parameters and resubmit the request if the operation failed."
- },
- "QueryNotSupported": {
- "Description": "Indicates that query is not supported on the implementation.",
- "Message": "Querying is not supported by the implementation.",
- "Severity": "Warning",
- "NumberOfArgs": 0,
- "Resolution": "Remove the query parameters and resubmit the request if the operation failed."
- },
- "SessionLimitExceeded": {
- "Description": "Indicates that a session establishment has been requested but the operation failed due to the number of simultaneous sessions exceeding the limit of the implementation.",
- "Message": "The session establishment failed due to the number of simultaneous sessions exceeding the limit of the implementation.",
- "Severity": "Critical",
- "NumberOfArgs": 0,
- "Resolution": "Reduce the number of other sessions before trying to establish the session or increase the limit of simultaneous sessions (if supported)."
- },
- "EventSubscriptionLimitExceeded": {
- "Description": "Indicates that a event subscription establishment has been requested but the operation failed due to the number of simultaneous connection exceeding the limit of the implementation.",
- "Message": "The event subscription failed due to the number of simultaneous subscriptions exceeding the limit of the implementation.",
- "Severity": "Critical",
- "NumberOfArgs": 0,
- "Resolution": "Reduce the number of other subscriptions before trying to establish the event subscription or increase the limit of simultaneous subscriptions (if supported)."
- },
- "ResourceCannotBeDeleted": {
- "Description": "Indicates that a delete operation was attempted on a resource that cannot be deleted.",
- "Message": "The delete request failed because the resource requested cannot be deleted.",
- "Severity": "Critical",
- "NumberOfArgs": 0,
- "Resolution": "Do not attempt to delete a non-deletable resource."
- },
- "ResourceInUse": {
- "Description": "Indicates that a change was requested to a resource but the change was rejected due to the resource being in use or transition.",
- "Message": "The change to the requested resource failed because the resource is in use or in transition.",
- "Severity": "Warning",
- "NumberOfArgs": 0,
- "Resolution": "Remove the condition and resubmit the request if the operation failed."
- },
- "ResourceAlreadyExists": {
- "Description": "Indicates that a resource change or creation was attempted but that the operation cannot proceed because the resource already exists.",
- "Message": "The requested resource of type %1 with the property %2 with the value %3 already exists.",
- "Severity": "Critical",
- "NumberOfArgs": 3,
- "ParamTypes": [
- "string",
- "string",
- "string"
- ],
- "Resolution": "Do not repeat the create operation as the resource has already been created."
- },
- "ResourceNotFound": {
- "Description": "Indicates that the operation expected a resource identifier that corresponds to an existing resource but one was not found.",
- "Message": "The requested resource of type %1 named %2 was not found.",
- "Severity": "Critical",
- "NumberOfArgs": 2,
- "ParamTypes": [
- "string",
- "string"
- ],
- "Resolution": "Provide a valid resource identifier and resubmit the request."
- },
- "CreateFailedMissingReqProperties": {
- "Description": "Indicates that a create was attempted on a resource but that properties that are required for the create operation were missing from the request.",
- "Message": "The create operation failed because the required property %1 was missing from the request.",
- "Severity": "Critical",
- "NumberOfArgs": 1,
- "ParamTypes": [
- "string"
- ],
- "Resolution": "Correct the body to include the required property with a valid value and resubmit the request if the operation failed."
- },
- "CreateLimitReachedForResource": {
- "Description": "Indicates that no more resources can be created on the resource as it has reached its create limit.",
- "Message": "The create operation failed because the resource has reached the limit of possible resources.",
- "Severity": "Critical",
- "NumberOfArgs": 0,
- "Resolution": "Either delete resources and resubmit the request if the operation failed or do not resubmit the request."
- },
- "ServiceShuttingDown": {
- "Description": "Indicates that the operation failed as the service is shutting down, such as when the service reboots.",
- "Message": "The operation failed because the service is shutting down and can no longer take incoming requests.",
- "Severity": "Critical",
- "NumberOfArgs": 0,
- "Resolution": "When the service becomes available, resubmit the request if the operation failed."
- },
- "ServiceInUnknownState": {
- "Description": "Indicates that the operation failed because the service is in an unknown state and cannot accept additional requests.",
- "Message": "The operation failed because the service is in an unknown state and can no longer take incoming requests.",
- "Severity": "Critical",
- "NumberOfArgs": 0,
- "Resolution": "Restart the service and resubmit the request if the operation failed."
- },
- "NoValidSession": {
- "Description": "Indicates that the operation failed because a valid session is required in order to access any resources.",
- "Message": "There is no valid session established with the implementation.",
- "Severity": "Critical",
- "NumberOfArgs": 0,
- "Resolution": "Establish as session before attempting any operations."
- },
- "InsufficientPrivilege": {
- "Description": "Indicates that the credentials associated with the established session do not have sufficient privileges for the requested operation",
- "Message": "There are insufficient privileges for the account or credentials associated with the current session to perform the requested operation.",
- "Severity": "Critical",
- "NumberOfArgs": 0,
- "Resolution": "Either abandon the operation or change the associated access rights and resubmit the request if the operation failed."
- },
- "AccountModified": {
- "Description": "Indicates that the account was successfully modified.",
- "Message": "The account was successfully modified.",
- "Severity": "OK",
- "NumberOfArgs": 0,
- "Resolution": "No resolution is required."
- },
- "AccountNotModified": {
- "Description": "Indicates that the modification requested for the account was not successful.",
- "Message": "The account modification request failed.",
- "Severity": "Warning",
- "NumberOfArgs": 0,
- "Resolution": "The modification may have failed due to permission issues or issues with the request body."
- },
- "AccountRemoved": {
- "Description": "Indicates that the account was successfully removed.",
- "Message": "The account was successfully removed.",
- "Severity": "OK",
- "NumberOfArgs": 0,
- "Resolution": "No resolution is required."
- },
- "AccountForSessionNoLongerExists": {
- "Description": "Indicates that the account for the session has been removed, thus the session has been removed as well.",
- "Message": "The account for the current session has been removed, thus the current session has been removed as well.",
- "Severity": "OK",
- "NumberOfArgs": 0,
- "Resolution": "Attempt to connect with a valid account."
- },
- "InvalidObject": {
- "Description": "Indicates that the object in question is invalid according to the implementation. Examples include a firmware update malformed URI.",
- "Message": "The object at %1 is invalid.",
- "Severity": "Critical",
- "NumberOfArgs": 1,
- "ParamTypes": [
- "string"
- ],
- "Resolution": "Either the object is malformed or the URI is not correct. Correct the condition and resubmit the request if it failed."
- },
- "InternalError": {
- "Description": "Indicates that the request failed for an unknown internal error but that the service is still operational.",
- "Message": "The request failed due to an internal service error. The service is still operational.",
- "Severity": "Critical",
- "NumberOfArgs": 0,
- "Resolution": "Resubmit the request. If the problem persists, consider resetting the service."
- },
- "UnrecognizedRequestBody": {
- "Description": "Indicates that the service encountered an unrecognizable request body that could not even be interpreted as malformed JSON.",
- "Message": "The service detected a malformed request body that it was unable to interpret.",
- "Severity": "Warning",
- "NumberOfArgs": 0,
- "Resolution": "Correct the request body and resubmit the request if it failed."
- },
- "ResourceMissingAtURI": {
- "Description": "Indicates that the operation expected an image or other resource at the provided URI but none was found. Examples of this are in requests that require URIs like Firmware Update.",
- "Message": "The resource at the URI %1 was not found.",
- "Severity": "Critical",
- "NumberOfArgs": 1,
- "ParamTypes": [
- "string"
- ],
- "Resolution": "Place a valid resource at the URI or correct the URI and resubmit the request."
- },
- "ResourceAtUriInUnknownFormat": {
- "Description": "Indicates that the URI was valid but the resource or image at that URI was in a format not supported by the service.",
- "Message": "The resource at %1 is in a format not recognized by the service.",
- "Severity": "Critical",
- "NumberOfArgs": 1,
- "ParamTypes": [
- "string"
- ],
- "Resolution": "Place an image or resource or file that is recognized by the service at the URI."
- },
- "ResourceAtUriUnauthorized": {
- "Description": "Indicates that the attempt to access the resource/file/image at the URI was unauthorized.",
- "Message": "While accessing the resource at %1, the service received an authorization error %2.",
- "Severity": "Critical",
- "NumberOfArgs": 2,
- "ParamTypes": [
- "string",
- "string"
- ],
- "Resolution": "Ensure that the appropriate access is provided for the service in order for it to access the URI."
- },
- "CouldNotEstablishConnection": {
- "Description": "Indicates that the attempt to access the resource/file/image at the URI was unsuccessful because a session could not be established.",
- "Message": "The service failed to establish a connection with the URI %1.",
- "Severity": "Critical",
- "NumberOfArgs": 1,
- "ParamTypes": [
- "string"
- ],
- "Resolution": "Ensure that the URI contains a valid and reachable node name, protocol information and other URI components."
- },
- "SourceDoesNotSupportProtocol": {
- "Description": "Indicates that while attempting to access, connect to or transfer a resource/file/image from another location that the other end of the connection did not support the protocol",
- "Message": "The other end of the connection at %1 does not support the specified protocol %2.",
- "Severity": "Critical",
- "NumberOfArgs": 2,
- "ParamTypes": [
- "string",
- "string"
- ],
- "Resolution": "Change protocols or URIs. "
- },
- "AccessDenied": {
- "Description": "Indicates that while attempting to access, connect to or transfer to/from another resource, the service denied access.",
- "Message": "While attempting to establish a connection to %1, the service denied access.",
- "Severity": "Critical",
- "NumberOfArgs": 1,
- "ParamTypes": [
- "string"
- ],
- "Resolution": "Attempt to ensure that the URI is correct and that the service has the appropriate credentials."
- },
- "ServiceTemporarilyUnavailable": {
- "Description": "Indicates the service is temporarily unavailable.",
- "Message": "The service is temporarily unavailable. Retry in %1 seconds.",
- "Severity": "Critical",
- "NumberOfArgs": 1,
- "ParamTypes": [
- "string"
- ],
- "Resolution": "Wait for the indicated retry duration and retry the operation."
- },
- "InvalidIndex": {
- "Description": "The Index is not valid.",
- "Message": "The Index %1 is not a valid offset into the array.",
- "Severity": "Warning",
- "NumberOfArgs": 1,
- "ParamTypes": [
- "number"
- ],
- "Resolution": "Verify the index value provided is within the bounds of the array."
- },
- "PropertyValueModified": {
- "Description": "Indicates that a property was given the correct value type but the value of that property was modified. Examples are truncated or rounded values.",
- "Message": "The property %1 was assigned the value %2 due to modification by the service.",
- "Severity": "Warning",
- "NumberOfArgs": 2,
- "ParamTypes": [
- "string",
- "string"
- ],
- "Resolution": "No resolution is required."
- },
- "ResourceInStandby": {
- "Description": "Indicates that the request could not be performed because the resource is in standby.",
- "Message": "The request could not be performed because the resource is in standby.",
- "Severity": "Critical",
- "NumberOfArgs": 0,
- "Resolution": "Ensure that the resource is in the correct power state and resubmit the request."
- },
- "ResourceExhaustion": {
- "Description": "Indicates that a resource could not satisfy the request due to some unavailability of resources. An example is that available capacity has been allocated.",
- "Message": "The resource %1 was unable to satisfy the request due to unavailability of resources.",
- "Severity": "Critical",
- "NumberOfArgs": 1,
- "ParamTypes": [
- "string"
- ],
- "Resolution": "Ensure that the resources are available and resubmit the request."
- },
- "StringValueTooLong": {
- "Description": "Indicates that a string value passed to the given resource exceeded its length limit. An example is when a shorter limit is imposed by an implementation than that allowed by the specification.",
- "Message": "The string %1 exceeds the length limit %2.",
- "Severity": "Warning",
- "NumberOfArgs": 2,
- "ParamTypes": [
- "string",
- "number"
- ],
- "Resolution": "Resubmit the request with an appropriate string length."
- }
- }
-}
diff --git a/redfish-core/scripts/error_messages/error_messages.cpp.in b/redfish-core/scripts/error_messages/error_messages.cpp.in
deleted file mode 100644
index 01b82a58ce..0000000000
--- a/redfish-core/scripts/error_messages/error_messages.cpp.in
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
-// Copyright (c) 2018 Intel Corporation
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-*/
-#include <error_messages.hpp>
-#include <crow/logging.h>
-
-namespace redfish {
-
-namespace messages {
-
-void addMessageToErrorJson(nlohmann::json& target,
- const nlohmann::json& message) {
- auto& error = target["error"];
-
- // If this is the first error message, fill in the information from the first
- // error message to the top level struct
- if (!error.is_object()) {
- auto message_id_iterator = message.find("MessageId");
- if (message_id_iterator == message.end()) {
- BMCWEB_LOG_CRITICAL << "Attempt to add error message without MessageId";
- return;
- }
-
- auto message_field_iterator = message.find("Message");
- if (message_field_iterator == message.end()) {
- BMCWEB_LOG_CRITICAL << "Attempt to add error message without Message";
- return;
- }
- // clang-format off
- error = {
- {"code", *message_id_iterator},
- {"message", *message_field_iterator}
- };
- // clang-format on
- } else {
- // More than 1 error occurred, so the message has to be generic
- error["code"] = std::string(messageVersionPrefix) + "GeneralError";
- error["message"] = "A general error has occurred. See ExtendedInfo for more"
- "information.";
- }
-
- // This check could technically be done in in the default construction
- // branch above, but because we need the pointer to the extended info field
- // anyway, it's more efficient to do it here.
- auto& extended_info = error[messages::messageAnnotation];
- if (!extended_info.is_array()) {
- extended_info = nlohmann::json::array();
- }
-
- extended_info.push_back(message);
-}
-
-void addMessageToJsonRoot(nlohmann::json& target,
- const nlohmann::json& message) {
- if (!target[messages::messageAnnotation].is_array()) {
- // Force object to be an array
- target[messages::messageAnnotation] = nlohmann::json::array();
- }
-
- target[messages::messageAnnotation].push_back(message);
-}
-
-void addMessageToJson(nlohmann::json& target, const nlohmann::json& message,
- const std::string& fieldPath) {
- nlohmann::json_pointer extendedInfo(fieldPath + messages::messageAnnotation);
-
- if (!target[extendedInfo].is_array()) {
- // Force object to be an array
- target[extendedInfo] = nlohmann::json::array();
- }
-
- // Object exists and it is an array so we can just push in the message
- target[extendedInfo].push_back(message);
-}
-
-/*********************************
- * AUTOGENERATED FUNCTIONS START *
- *********************************/
-
-/*<<<<<<AUTOGENERATED_FUNCTIONS_IMPLEMENTATIONS>>>>>>*/
-
-/*********************************
- * AUTOGENERATED FUNCTIONS END *
- *********************************/
-
-} // namespace messages
-
-} // namespace redifsh
diff --git a/redfish-core/scripts/error_messages/error_messages.hpp.in b/redfish-core/scripts/error_messages/error_messages.hpp.in
deleted file mode 100644
index b0f5c009d9..0000000000
--- a/redfish-core/scripts/error_messages/error_messages.hpp.in
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
-// Copyright (c) 2018 Intel Corporation
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-*/
-/****************************************************************
- * This is an auto-generated header which contains definitions
- * to use Redfish DMTF defined messages.
- *
- * This header contains preprocessor defines which wrap
- * preparation functions for message with given id. The message
- * ids can be retrieved from Base.__ver__.json file.
- ***************************************************************/
-#pragma once
-#include <nlohmann/json.hpp>
-
-namespace redfish {
-
-namespace messages {
-
-constexpr const char* messageVersionPrefix = "Base.1.2.0.";
-constexpr const char* messageAnnotation = "@Message.ExtendedInfo";
-
-/**
- * @brief Adds Message JSON object to error object
- *
- * @param[out] target Target JSON to which message will be added
- * @param[in] message Message JSON that should be added to target
- *
- * @return None
- */
-void addMessageToErrorJson(nlohmann::json& target,
- const nlohmann::json& message);
-
-/**
- * @brief Adds Message JSON object to target JSON
- *
- * @internal
- * This function has similar implementation to addMessageToJson(...), but
- * does not use nlohmann::json_pointer to avoid costly construction
- * @endinternal
- *
- * @param[out] target Target JSON to which message will be added
- * @param[in] message Message JSON that should be added to target
- *
- * @return None
- */
-void addMessageToJsonRoot(nlohmann::json& target,
- const nlohmann::json& message);
-
-/**
- * @brief Adds Message JSON object connected with specific field to target JSON
- *
- * @param[out] target Target JSON to which message will be added
- * @param[in] message Message JSON that should be added to target
- * @param[in] fieldPath Path of related field
- *
- * @return None
- */
-void addMessageToJson(nlohmann::json& target, const nlohmann::json& message,
- const std::string& fieldPath);
-
-/*********************************
- * AUTOGENERATED FUNCTIONS START *
- *********************************/
-
-/*<<<<<<AUTOGENERATED_FUNCTIONS_DECLARATIONS>>>>>>*/
-
-/*********************************
- * AUTOGENERATED FUNCTIONS END *
- *********************************/
-
-} // namespace messages
-
-} // namespace redfish
diff --git a/redfish-core/scripts/error_messages/error_messages.py b/redfish-core/scripts/error_messages/error_messages.py
deleted file mode 100644
index 0ab15fd866..0000000000
--- a/redfish-core/scripts/error_messages/error_messages.py
+++ /dev/null
@@ -1,332 +0,0 @@
-# Copyright (c) 2018 Intel Corporation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import json
-import os
-import re
-import sys
-
-# CONSTANTS
-# Containing namespace
-NAMESPACE = "redfish::messages::"
-# Single indentation
-INDENT = " " * 2
-# Include directory where created files will be stored
-AUTOGEN_PATH = ""
-# MessageRegistry JSON Path
-MESSAGE_REGISTRY_JSON_PATH = ""
-# Error messages target filename
-ERROR_MESSAGES_TARGET_FILENAME = "error_messages"
-# Script path
-SCRIPT_PATH = os.path.dirname(sys.argv[0])
-
-FORMATTING_FUNCTIONS_DECLARATIONS = []
-FORMATTING_FUNCTIONS_IMPLEMENTATIONS = []
-
-# Loaded MessageRegistry JSON
-MESSAGE_REGISTRY = {}
-
-# Path to output header file
-OUT_HEADER_PATH = ""
-# Path to output source file
-OUT_SOURCE_PATH = ""
-
-PARAM_TYPE_TO_CPP_TYPE = {
- "string": "std::string",
- "number": "int"
-}
-
-PARAM_TYPE_TO_FORMATTING_ARG = {
- "string": 'arg{}',
- "number": 'std::to_string(arg{})'
-}
-
-
-def verify_message(message_id):
- """
- Verifies message, by checking that all its parameter information is correct
-
- :param message_id: Id to be verified
- :return: True if message is OK, False otherwise
- """
- try:
- message_body = MESSAGE_REGISTRY["Messages"][message_id]["Message"]
- message_num_args = MESSAGE_REGISTRY["Messages"][message_id]["NumberOfArgs"]
- regex_find_all_args = '(%[0-9]{1})'
- found_args = re.findall(regex_find_all_args, message_body)
-
- if message_num_args == 0:
- # Verify that there are no %<digit> in message body
- if len(found_args) != 0:
- return False
- else:
- param_types = MESSAGE_REGISTRY["Messages"][message_id]["ParamTypes"]
-
- if message_num_args != len(param_types):
- return False
- else:
- # Verify that param types are not unknown
- for param_type in param_types:
- if not param_type in PARAM_TYPE_TO_CPP_TYPE:
- print "Unknown param type " + param_type
-
- return False
-
- # Verify that there are as many args as there should be
- if len(found_args) != message_num_args:
- return False
-
- # Verify that all required args exist
- for i in range(1, message_num_args + 1):
- found_args.remove("%" + str(i))
-
- if len(found_args) != 0:
- return False
- except:
- return False
-
- return True
-
-
-def create_function_brief(message_id):
- """
- Creates dOxygen brief for formatting function of given message
-
- :param message_id: Id of message for which brief should be created
- :return: Created @brief message
- """
- return "@brief Formats " + message_id + " message into JSON"
-
-
-def create_message_body_for_doxy(message_id):
- """
- Creates formatted message body for dOxygen comment to lookup message without looking into function code
-
- :param message_id: Id of message for which message body for doxy should be created
- :return: Created message
- """
- body = MESSAGE_REGISTRY["Messages"][message_id]["Message"]
- num_params = MESSAGE_REGISTRY["Messages"][message_id]["NumberOfArgs"]
-
- for param_idx in range(0, num_params):
- formatting_str = '%' + str(param_idx + 1)
-
- body = body.replace(formatting_str, '<arg' + str(param_idx) + '>');
-
- return 'Message body: "' + body + '"'
-
-
-def create_full_doxygen_comment(message_id):
- """
- Creates full dOxygen comment with given data
-
- :param message_id: Id of message for which's formatting function comment should be created
- :return:
- """
- num_params = MESSAGE_REGISTRY["Messages"][message_id]["NumberOfArgs"]
-
- out_comment = "/**\n" + \
- " * " + create_function_brief(message_id) + "\n" \
- " * " + create_message_body_for_doxy(message_id) + "\n" \
- " *\n"
-
- for param_idx in range(1, num_params + 1):
- out_comment += " * @param[in] arg" + str(param_idx) + " Parameter of message that will replace %" +\
- str(param_idx) + " in its body.\n"
-
- out_comment += " *\n"
- out_comment += " * @returns Message " + message_id + " formatted to JSON"
- out_comment += " */\n"
-
- return out_comment
-
-
-def create_internal_doxygen_comment(message_id):
- """
- Creates internal dOxygen comment with given data
-
- :param message_id: Id of message for which's formatting function comment should be created
- :return:
- """
- out_comment = "/**\n" + \
- " * @internal\n" + \
- " * " + create_function_brief(message_id) + "\n" + \
- " *\n" + \
- " * See header file for more information\n" + \
- " * @endinternal\n" + \
- " */\n"
-
- return out_comment
-
-
-def create_message_function_head(message_id):
- """
- Create header like nlohmann::json <msg_id_with_first_letter_lowercase>(...)
-
- :param message_id: Id of message for which function header should be created
- :return: Created function header
- """
- function_name = message_id[:1].lower() + message_id[1:]
- function_arguments = ""
-
- if MESSAGE_REGISTRY["Messages"][message_id]["NumberOfArgs"] != 0:
- param_types = MESSAGE_REGISTRY["Messages"][message_id]["ParamTypes"]
- params = []
-
- for param_idx in range(0, len(param_types)):
- params.append("const " + PARAM_TYPE_TO_CPP_TYPE[param_types[param_idx]] + "& arg" + str(param_idx + 1))
-
- function_arguments = ', '.join(params)
-
- return "nlohmann::json " + function_name + "(" + function_arguments + ")"
-
-
-def create_message_function_body(message_id, is_complex):
- """
- Creates format function body for message without parameters
-
- :param message_id: Id of message for which format function body should be created
- :return: Format function body for given message
- """
- message_data = MESSAGE_REGISTRY["Messages"][message_id]
- message_body = message_data["Message"]
-
- if is_complex:
- param_types = message_data["ParamTypes"]
-
- for param_idx in range(0, len(param_types)):
- formatting_str = '%' + str(param_idx + 1)
- formatting_arg = PARAM_TYPE_TO_FORMATTING_ARG[param_types[param_idx]].format(str(param_idx + 1))
-
- message_body = message_body.replace(formatting_str, '" + ' + formatting_arg + ' + "');
-
- body = ' {\n' + \
- INDENT + 'return nlohmann::json{' + '\n' + \
- INDENT + INDENT + '{"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},' + '\n' + \
- INDENT + INDENT + '{"MessageId", "' + MESSAGE_REGISTRY["Id"] + "." + message_id + '"},' + '\n' + \
- INDENT + INDENT + '{"Message", "' + message_body + '"},' + '\n' + \
- INDENT + INDENT + '{"Severity", "' + message_data["Severity"] + '"},' + '\n' + \
- INDENT + INDENT + '{"Resolution", "' + message_data["Resolution"] + '"}' + '\n' + \
- INDENT + '};' + '\n' + \
- '}'
-
- return body
-
-
-def process_message(message_id):
- """
- Processes given message and adds created definitions to appropriate globals
- - Creates MessageId enumeration value for given message
- - Creates macro to use given message in format:
- a) For argument-less messages - FORMAT_REDFISH_MESSAGE_<message_id>
- b) For parametrized messages - FORMAT_REDFISH_MESSAGE_<message_id>(arg1, arg2, ...)
- - Creates structure definition for message
-
- :param message_id: ID of message that should be processed
-
- :return: None
- """
- if verify_message(message_id):
- foo_head = create_message_function_head(message_id)
- foo_body = create_message_function_body(message_id,
- MESSAGE_REGISTRY["Messages"][message_id]["NumberOfArgs"] != 0)
-
- # For header file
- full_doxy_comment = create_full_doxygen_comment(message_id)
-
- FORMATTING_FUNCTIONS_DECLARATIONS.append(full_doxy_comment + foo_head + ';\n')
-
- # For source file
- internal_doxy_comment = create_internal_doxygen_comment(message_id)
-
- format_foo_impl = internal_doxy_comment + foo_head + foo_body
-
- FORMATTING_FUNCTIONS_IMPLEMENTATIONS.append(format_foo_impl)
- else:
- print message_id + " is not correctly defined! It will be omitted"
-
-
-def process_messages():
- """
- Iterates through all messages and processes each of them
-
- :return: None
- """
- for message_id in MESSAGE_REGISTRY[u'Messages']:
- process_message(message_id)
-
-
-def prepare_declarations():
- return '\n'.join(FORMATTING_FUNCTIONS_DECLARATIONS)
-
-
-def prepare_implementations():
- return '\n\n'.join(FORMATTING_FUNCTIONS_IMPLEMENTATIONS)
-
-
-def generate_error_messages_cpp():
- """
- Replaces placeholders inside source file with generated data
-
- :return: None
- """
- with open(SCRIPT_PATH + "/" + ERROR_MESSAGES_TARGET_FILENAME + ".cpp.in", 'r') as source_file_template:
- file_contents = source_file_template.read()
-
- file_contents = file_contents.replace("/*<<<<<<AUTOGENERATED_FUNCTIONS_IMPLEMENTATIONS>>>>>>*/",
- prepare_implementations())
-
- with open(OUT_SOURCE_PATH, "w") as source_file_target:
- source_file_target.write(file_contents)
-
-
-def generate_error_messages_hpp():
- """
- Replaces placeholders inside header file with generated data
-
- :return: None
- """
- with open(SCRIPT_PATH + "/" + ERROR_MESSAGES_TARGET_FILENAME + ".hpp.in", 'r') as header_file_template:
- file_contents = header_file_template.read()
-
- # Add definitions
- file_contents = file_contents.replace("/*<<<<<<AUTOGENERATED_FUNCTIONS_DECLARATIONS>>>>>>*/",
- prepare_declarations())
-
- with open(OUT_HEADER_PATH, "w") as header_file_target:
- header_file_target.write(file_contents)
-
-
-if __name__ == "__main__":
- if len(sys.argv) < 2:
- sys.exit("Not enough arguments. Required syntax is:\n error_messages.py <autogen_dir> <messages_json>")
- else:
- AUTOGEN_PATH = sys.argv[1]
- MESSAGE_REGISTRY_JSON_PATH = sys.argv[2]
-
- MESSAGE_REGISTRY = json.load(open(MESSAGE_REGISTRY_JSON_PATH))
-
- OUT_HEADER_PATH = AUTOGEN_PATH + "/" + ERROR_MESSAGES_TARGET_FILENAME + ".hpp"
- OUT_SOURCE_PATH = AUTOGEN_PATH + "/" + ERROR_MESSAGES_TARGET_FILENAME + ".cpp"
-
- # Make sure that files directory exists
- if not os.path.exists(AUTOGEN_PATH):
- os.makedirs(AUTOGEN_PATH)
-
- # Process found messages
- process_messages()
-
- # Generate files
- generate_error_messages_cpp()
- generate_error_messages_hpp()
diff --git a/redfish-core/src/error_messages.cpp b/redfish-core/src/error_messages.cpp
index a8077629ac..949ce0fef3 100644
--- a/redfish-core/src/error_messages.cpp
+++ b/redfish-core/src/error_messages.cpp
@@ -23,8 +23,8 @@ namespace redfish
namespace messages
{
-void addMessageToErrorJson(nlohmann::json& target,
- const nlohmann::json& message)
+static void addMessageToErrorJson(nlohmann::json& target,
+ const nlohmann::json& message)
{
auto& error = target["error"];
@@ -75,7 +75,8 @@ void addMessageToErrorJson(nlohmann::json& target,
extended_info.push_back(message);
}
-void addMessageToJsonRoot(nlohmann::json& target, const nlohmann::json& message)
+static void addMessageToJsonRoot(nlohmann::json& target,
+ const nlohmann::json& message)
{
if (!target[messages::messageAnnotation].is_array())
{
@@ -86,8 +87,9 @@ void addMessageToJsonRoot(nlohmann::json& target, const nlohmann::json& message)
target[messages::messageAnnotation].push_back(message);
}
-void addMessageToJson(nlohmann::json& target, const nlohmann::json& message,
- const std::string& fieldPath)
+static void addMessageToJson(nlohmann::json& target,
+ const nlohmann::json& message,
+ const std::string& fieldPath)
{
nlohmann::json_pointer<nlohmann::json> extendedInfo(
fieldPath + messages::messageAnnotation);
@@ -102,10 +104,6 @@ void addMessageToJson(nlohmann::json& target, const nlohmann::json& message,
target[extendedInfo].push_back(message);
}
-/*********************************
- * AUTOGENERATED FUNCTIONS START *
- *********************************/
-
/**
* @internal
* @brief Formats ResourceInUse message into JSON
@@ -113,18 +111,22 @@ void addMessageToJson(nlohmann::json& target, const nlohmann::json& message,
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceInUse()
+void resourceInUse(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceInUse"},
- {"Message", "The change to the requested resource failed because the "
- "resource is in "
- "use or in transition."},
- {"Severity", "Warning"},
- {"Resolution",
- "Remove the condition and resubmit the request if the operation "
- "failed."}};
+ res.result(boost::beast::http::status::service_unavailable);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceInUse"},
+ {"Message",
+ "The change to the requested resource failed because the "
+ "resource is in "
+ "use or in transition."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Remove the condition and resubmit the request if the operation "
+ "failed."}});
}
/**
@@ -134,17 +136,21 @@ nlohmann::json resourceInUse()
* See header file for more information
* @endinternal
*/
-nlohmann::json malformedJSON()
+void malformedJSON(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.MalformedJSON"},
- {"Message", "The request body submitted was malformed JSON and could "
- "not be parsed "
- "by the receiving service."},
- {"Severity", "Critical"},
- {"Resolution", "Ensure that the request body is valid JSON and "
- "resubmit the request."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.MalformedJSON"},
+ {"Message",
+ "The request body submitted was malformed JSON and could "
+ "not be parsed "
+ "by the receiving service."},
+ {"Severity", "Critical"},
+ {"Resolution", "Ensure that the request body is valid JSON and "
+ "resubmit the request."}});
}
/**
@@ -154,16 +160,20 @@ nlohmann::json malformedJSON()
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceMissingAtURI(const std::string& arg1)
+void resourceMissingAtURI(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceMissingAtURI"},
- {"Message", "The resource at the URI " + arg1 + " was not found."},
- {"Severity", "Critical"},
- {"Resolution", "Place a valid resource at the URI or correct the URI "
- "and resubmit the "
- "request."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceMissingAtURI"},
+ {"Message", "The resource at the URI " + arg1 + " was not found."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Place a valid resource at the URI or correct the URI "
+ "and resubmit the "
+ "request."}});
}
/**
@@ -173,21 +183,25 @@ nlohmann::json resourceMissingAtURI(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json actionParameterValueFormatError(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3)
-{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ActionParameterValueFormatError"},
- {"Message",
- "The value " + arg1 + " for the parameter " + arg2 +
- " in the action " + arg3 +
- " is of a different format than the parameter can accept."},
- {"Severity", "Warning"},
- {"Resolution",
- "Correct the value for the parameter in the request body and resubmit "
- "the request if the operation failed."}};
+void actionParameterValueFormatError(crow::Response& res,
+ const std::string& arg1,
+ const std::string& arg2,
+ const std::string& arg3)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ActionParameterValueFormatError"},
+ {"Message",
+ "The value " + arg1 + " for the parameter " + arg2 +
+ " in the action " + arg3 +
+ " is of a different format than the parameter can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the parameter in the request "
+ "body and resubmit "
+ "the request if the operation failed."}});
}
/**
@@ -197,18 +211,46 @@ nlohmann::json actionParameterValueFormatError(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json internalError()
+void internalError(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.InternalError"},
- {"Message",
- "The request failed due to an internal service error. The service is "
- "still operational."},
- {"Severity", "Critical"},
- {"Resolution", "Resubmit the request. If the problem persists, "
- "consider resetting the "
- "service."}};
+ res.result(boost::beast::http::status::internal_server_error);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.InternalError"},
+ {"Message", "The request failed due to an internal service error. "
+ "The service is "
+ "still operational."},
+ {"Severity", "Critical"},
+ {"Resolution", "Resubmit the request. If the problem persists, "
+ "consider resetting the "
+ "service."}});
+}
+
+/**
+ * @internal
+ * @brief Formats InternalError message into JSON for the specified field
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void internalError(crow::Response& res, const std::string& field)
+{
+ res.result(boost::beast::http::status::internal_server_error);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.InternalError"},
+ {"Message", "The request failed due to an internal service error. "
+ "The service is "
+ "still operational."},
+ {"Severity", "Critical"},
+ {"Resolution", "Resubmit the request. If the problem persists, "
+ "consider resetting the "
+ "service."}},
+ field);
}
/**
@@ -218,17 +260,20 @@ nlohmann::json internalError()
* See header file for more information
* @endinternal
*/
-nlohmann::json unrecognizedRequestBody()
+void unrecognizedRequestBody(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.UnrecognizedRequestBody"},
- {"Message",
- "The service detected a malformed request body that it was unable to "
- "interpret."},
- {"Severity", "Warning"},
- {"Resolution",
- "Correct the request body and resubmit the request if it failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.UnrecognizedRequestBody"},
+ {"Message", "The service detected a malformed request body that it "
+ "was unable to "
+ "interpret."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the request body and resubmit the request "
+ "if it failed."}});
}
/**
@@ -238,19 +283,22 @@ nlohmann::json unrecognizedRequestBody()
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceAtUriUnauthorized(const std::string& arg1,
- const std::string& arg2)
+void resourceAtUriUnauthorized(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceAtUriUnauthorized"},
- {"Message", "While accessing the resource at " + arg1 +
- ", the service received an authorization error " +
- arg2 + "."},
- {"Severity", "Critical"},
- {"Resolution",
- "Ensure that the appropriate access is provided for the service in "
- "order for it to access the URI."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceAtUriUnauthorized"},
+ {"Message", "While accessing the resource at " + arg1 +
+ ", the service received an authorization error " +
+ arg2 + "."},
+ {"Severity", "Critical"},
+ {"Resolution", "Ensure that the appropriate access is provided for "
+ "the service in "
+ "order for it to access the URI."}});
}
/**
@@ -260,19 +308,22 @@ nlohmann::json resourceAtUriUnauthorized(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json actionParameterUnknown(const std::string& arg1,
- const std::string& arg2)
+void actionParameterUnknown(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ActionParameterUnknown"},
- {"Message", "The action " + arg1 +
- " was submitted with the invalid parameter " + arg2 +
- "."},
- {"Severity", "Warning"},
- {"Resolution",
- "Correct the invalid parameter and resubmit the request if the "
- "operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ActionParameterUnknown"},
+ {"Message", "The action " + arg1 +
+ " was submitted with the invalid parameter " +
+ arg2 + "."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Correct the invalid parameter and resubmit the request if the "
+ "operation failed."}});
}
/**
@@ -282,16 +333,20 @@ nlohmann::json actionParameterUnknown(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceCannotBeDeleted()
+void resourceCannotBeDeleted(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceCannotBeDeleted"},
- {"Message",
- "The delete request failed because the resource requested cannot be "
- "deleted."},
- {"Severity", "Critical"},
- {"Resolution", "Do not attempt to delete a non-deletable resource."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceCannotBeDeleted"},
+ {"Message", "The delete request failed because the resource "
+ "requested cannot be "
+ "deleted."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Do not attempt to delete a non-deletable resource."}});
}
/**
@@ -301,16 +356,20 @@ nlohmann::json resourceCannotBeDeleted()
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyDuplicate(const std::string& arg1)
+void propertyDuplicate(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyDuplicate"},
- {"Message", "The property " + arg1 + " was duplicated in the request."},
- {"Severity", "Warning"},
- {"Resolution",
- "Remove the duplicate property from the request body and resubmit the "
- "request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyDuplicate"},
+ {"Message",
+ "The property " + arg1 + " was duplicated in the request."},
+ {"Severity", "Warning"},
+ {"Resolution", "Remove the duplicate property from the request "
+ "body and resubmit the "
+ "request if the operation failed."}});
}
/**
@@ -320,16 +379,19 @@ nlohmann::json propertyDuplicate(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json serviceTemporarilyUnavailable(const std::string& arg1)
+void serviceTemporarilyUnavailable(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ServiceTemporarilyUnavailable"},
- {"Message", "The service is temporarily unavailable. Retry in " +
- arg1 + " seconds."},
- {"Severity", "Critical"},
- {"Resolution",
- "Wait for the indicated retry duration and retry the operation."}};
+ res.result(boost::beast::http::status::service_unavailable);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ServiceTemporarilyUnavailable"},
+ {"Message", "The service is temporarily unavailable. Retry in " +
+ arg1 + " seconds."},
+ {"Severity", "Critical"},
+ {"Resolution", "Wait for the indicated retry duration and retry "
+ "the operation."}});
}
/**
@@ -339,20 +401,22 @@ nlohmann::json serviceTemporarilyUnavailable(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceAlreadyExists(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3)
+void resourceAlreadyExists(crow::Response& res, const std::string& arg1,
+ const std::string& arg2, const std::string& arg3)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceAlreadyExists"},
- {"Message", "The requested resource of type " + arg1 +
- " with the property " + arg2 + " with the value " +
- arg3 + " already exists."},
- {"Severity", "Critical"},
- {"Resolution",
- "Do not repeat the create operation as the resource has already been "
- "created."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceAlreadyExists"},
+ {"Message", "The requested resource of type " + arg1 +
+ " with the property " + arg2 + " with the value " +
+ arg3 + " already exists."},
+ {"Severity", "Critical"},
+ {"Resolution", "Do not repeat the create operation as the resource "
+ "has already been "
+ "created."}});
}
/**
@@ -362,16 +426,21 @@ nlohmann::json resourceAlreadyExists(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json accountForSessionNoLongerExists()
+void accountForSessionNoLongerExists(crow::Response& res,
+ const std::string& fieldPath)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.AccountForSessionNoLongerExists"},
- {"Message", "The account for the current session has been removed, "
- "thus the current "
- "session has been removed as well."},
- {"Severity", "OK"},
- {"Resolution", "Attempt to connect with a valid account."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.AccountForSessionNoLongerExists"},
+ {"Message", "The account for the current session has been removed, "
+ "thus the current "
+ "session has been removed as well."},
+ {"Severity", "OK"},
+ {"Resolution", "Attempt to connect with a valid account."}},
+ fieldPath);
}
/**
@@ -381,18 +450,23 @@ nlohmann::json accountForSessionNoLongerExists()
* See header file for more information
* @endinternal
*/
-nlohmann::json createFailedMissingReqProperties(const std::string& arg1)
+void createFailedMissingReqProperties(crow::Response& res,
+ const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.CreateFailedMissingReqProperties"},
- {"Message",
- "The create operation failed because the required property " + arg1 +
- " was missing from the request."},
- {"Severity", "Critical"},
- {"Resolution",
- "Correct the body to include the required property with a valid value "
- "and resubmit the request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.CreateFailedMissingReqProperties"},
+ {"Message",
+ "The create operation failed because the required property " +
+ arg1 + " was missing from the request."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Correct the body to include the required property with a valid "
+ "value "
+ "and resubmit the request if the operation failed."}});
}
/**
@@ -402,19 +476,50 @@ nlohmann::json createFailedMissingReqProperties(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyValueFormatError(const std::string& arg1,
- const std::string& arg2)
+void propertyValueFormatError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyValueFormatError"},
- {"Message",
- "The value " + arg1 + " for the property " + arg2 +
- " is of a different format than the property can accept."},
- {"Severity", "Warning"},
- {"Resolution",
- "Correct the value for the property in the request body and resubmit "
- "the request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyValueFormatError"},
+ {"Message",
+ "The value " + arg1 + " for the property " + arg2 +
+ " is of a different format than the property can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the property in the request "
+ "body and resubmit "
+ "the request if the operation failed."}});
+}
+
+/**
+ * @internal
+ * @brief Formats PropertyValueFormatError message into JSON for the specified
+ * property
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void propertyValueFormatError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string property)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyValueFormatError"},
+ {"Message",
+ "The value " + arg1 + " for the property " + arg2 +
+ " is of a different format than the property can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the property in the request "
+ "body and resubmit "
+ "the request if the operation failed."}},
+ property);
}
/**
@@ -424,18 +529,49 @@ nlohmann::json propertyValueFormatError(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyValueNotInList(const std::string& arg1,
- const std::string& arg2)
+void propertyValueNotInList(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyValueNotInList"},
+ {"Message", "The value " + arg1 + " for the property " + arg2 +
+ " is not in the list of acceptable values."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Choose a value from the enumeration list that the implementation "
+ "can "
+ "support and resubmit the request if the operation failed."}});
+}
+
+/**
+ * @internal
+ * @brief Formats PropertyValueNotInList message into JSON for the specified
+ * property
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void propertyValueNotInList(crow::Response& res, const std::string& arg1,
+ const std::string& arg2, const std::string property)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyValueNotInList"},
- {"Message", "The value " + arg1 + " for the property " + arg2 +
- " is not in the list of acceptable values."},
- {"Severity", "Warning"},
- {"Resolution",
- "Choose a value from the enumeration list that the implementation can "
- "support and resubmit the request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyValueNotInList"},
+ {"Message", "The value " + arg1 + " for the property " + arg2 +
+ " is not in the list of acceptable values."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Choose a value from the enumeration list that the implementation "
+ "can "
+ "support and resubmit the request if the operation failed."}},
+ property);
}
/**
@@ -445,17 +581,20 @@ nlohmann::json propertyValueNotInList(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceAtUriInUnknownFormat(const std::string& arg1)
+void resourceAtUriInUnknownFormat(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceAtUriInUnknownFormat"},
- {"Message", "The resource at " + arg1 +
- " is in a format not recognized by the service."},
- {"Severity", "Critical"},
- {"Resolution",
- "Place an image or resource or file that is recognized by the service "
- "at the URI."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceAtUriInUnknownFormat"},
+ {"Message", "The resource at " + arg1 +
+ " is in a format not recognized by the service."},
+ {"Severity", "Critical"},
+ {"Resolution", "Place an image or resource or file that is "
+ "recognized by the service "
+ "at the URI."}});
}
/**
@@ -465,18 +604,21 @@ nlohmann::json resourceAtUriInUnknownFormat(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json serviceInUnknownState()
+void serviceInUnknownState(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ServiceInUnknownState"},
- {"Message",
- "The operation failed because the service is in an unknown state and "
- "can no longer take incoming requests."},
- {"Severity", "Critical"},
- {"Resolution",
- "Restart the service and resubmit the request if the operation "
- "failed."}};
+ res.result(boost::beast::http::status::service_unavailable);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ServiceInUnknownState"},
+ {"Message", "The operation failed because the service is in an "
+ "unknown state and "
+ "can no longer take incoming requests."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Restart the service and resubmit the request if the operation "
+ "failed."}});
}
/**
@@ -486,19 +628,23 @@ nlohmann::json serviceInUnknownState()
* See header file for more information
* @endinternal
*/
-nlohmann::json eventSubscriptionLimitExceeded()
+void eventSubscriptionLimitExceeded(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.EventSubscriptionLimitExceeded"},
- {"Message",
- "The event subscription failed due to the number of simultaneous "
- "subscriptions exceeding the limit of the implementation."},
- {"Severity", "Critical"},
- {"Resolution",
- "Reduce the number of other subscriptions before trying to establish "
- "the event subscription or increase the limit of simultaneous "
- "subscriptions (if supported)."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.EventSubscriptionLimitExceeded"},
+ {"Message",
+ "The event subscription failed due to the number of simultaneous "
+ "subscriptions exceeding the limit of the implementation."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Reduce the number of other subscriptions before trying to "
+ "establish "
+ "the event subscription or increase the limit of simultaneous "
+ "subscriptions (if supported)."}});
}
/**
@@ -508,18 +654,22 @@ nlohmann::json eventSubscriptionLimitExceeded()
* See header file for more information
* @endinternal
*/
-nlohmann::json actionParameterMissing(const std::string& arg1,
- const std::string& arg2)
+void actionParameterMissing(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ActionParameterMissing"},
- {"Message", "The action " + arg1 + " requires the parameter " + arg2 +
- " to be present in the request body."},
- {"Severity", "Critical"},
- {"Resolution", "Supply the action with the required parameter in the "
- "request body when "
- "the request is resubmitted."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ActionParameterMissing"},
+ {"Message", "The action " + arg1 + " requires the parameter " +
+ arg2 + " to be present in the request body."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Supply the action with the required parameter in the "
+ "request body when "
+ "the request is resubmitted."}});
}
/**
@@ -529,16 +679,20 @@ nlohmann::json actionParameterMissing(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json stringValueTooLong(const std::string& arg1, const int& arg2)
+void stringValueTooLong(crow::Response& res, const std::string& arg1,
+ const int& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.StringValueTooLong"},
- {"Message", "The string " + arg1 + " exceeds the length limit " +
- std::to_string(arg2) + "."},
- {"Severity", "Warning"},
- {"Resolution",
- "Resubmit the request with an appropriate string length."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.StringValueTooLong"},
+ {"Message", "The string " + arg1 + " exceeds the length limit " +
+ std::to_string(arg2) + "."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Resubmit the request with an appropriate string length."}});
}
/**
@@ -548,19 +702,50 @@ nlohmann::json stringValueTooLong(const std::string& arg1, const int& arg2)
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyValueTypeError(const std::string& arg1,
- const std::string& arg2)
+void propertyValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyValueTypeError"},
+ {"Message",
+ "The value " + arg1 + " for the property " + arg2 +
+ " is of a different type than the property can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the property in the request "
+ "body and resubmit "
+ "the request if the operation failed."}});
+}
+
+/**
+ * @internal
+ * @brief Formats PropertyValueTypeError message into JSON for the specified
+ * property
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void propertyValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string& property)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyValueTypeError"},
- {"Message",
- "The value " + arg1 + " for the property " + arg2 +
- " is of a different type than the property can accept."},
- {"Severity", "Warning"},
- {"Resolution",
- "Correct the value for the property in the request body and resubmit "
- "the request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyValueTypeError"},
+ {"Message",
+ "The value " + arg1 + " for the property " + arg2 +
+ " is of a different type than the property can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the property in the request "
+ "body and resubmit "
+ "the request if the operation failed."}},
+ property);
}
/**
@@ -570,17 +755,20 @@ nlohmann::json propertyValueTypeError(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceNotFound(const std::string& arg1,
- const std::string& arg2)
+void resourceNotFound(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceNotFound"},
- {"Message", "The requested resource of type " + arg1 + " named " +
- arg2 + " was not found."},
- {"Severity", "Critical"},
- {"Resolution",
- "Provide a valid resource identifier and resubmit the request."}};
+ res.result(boost::beast::http::status::not_found);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceNotFound"},
+ {"Message", "The requested resource of type " + arg1 + " named " +
+ arg2 + " was not found."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Provide a valid resource identifier and resubmit the request."}});
}
/**
@@ -590,18 +778,21 @@ nlohmann::json resourceNotFound(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json couldNotEstablishConnection(const std::string& arg1)
+void couldNotEstablishConnection(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.CouldNotEstablishConnection"},
- {"Message",
- "The service failed to establish a Connection with the URI " + arg1 +
- "."},
- {"Severity", "Critical"},
- {"Resolution", "Ensure that the URI contains a valid and reachable "
- "node name, protocol "
- "information and other URI components."}};
+ res.result(boost::beast::http::status::not_found);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.CouldNotEstablishConnection"},
+ {"Message",
+ "The service failed to establish a Connection with the URI " +
+ arg1 + "."},
+ {"Severity", "Critical"},
+ {"Resolution", "Ensure that the URI contains a valid and reachable "
+ "node name, protocol "
+ "information and other URI components."}});
}
/**
@@ -611,18 +802,50 @@ nlohmann::json couldNotEstablishConnection(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyNotWritable(const std::string& arg1)
+void propertyNotWritable(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyNotWritable"},
- {"Message",
- "The property " + arg1 +
- " is a read only property and cannot be assigned a value."},
- {"Severity", "Warning"},
- {"Resolution", "Remove the property from the request body and resubmit "
- "the request if "
- "the operation failed."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyNotWritable"},
+ {"Message",
+ "The property " + arg1 +
+ " is a read only property and cannot be assigned a value."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Remove the property from the request body and resubmit "
+ "the request if "
+ "the operation failed."}});
+}
+
+/**
+ * @internal
+ * @brief Formats PropertyNotWritable message into JSON for the specified
+ * property
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void propertyNotWritable(crow::Response& res, const std::string& arg1,
+ const std::string& property)
+{
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyNotWritable"},
+ {"Message",
+ "The property " + arg1 +
+ " is a read only property and cannot be assigned a value."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Remove the property from the request body and resubmit "
+ "the request if "
+ "the operation failed."}},
+ property);
}
/**
@@ -632,19 +855,22 @@ nlohmann::json propertyNotWritable(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json queryParameterValueTypeError(const std::string& arg1,
- const std::string& arg2)
+void queryParameterValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.QueryParameterValueTypeError"},
- {"Message",
- "The value " + arg1 + " for the query parameter " + arg2 +
- " is of a different type than the parameter can accept."},
- {"Severity", "Warning"},
- {"Resolution", "Correct the value for the query parameter in the "
- "request and resubmit "
- "the request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.QueryParameterValueTypeError"},
+ {"Message",
+ "The value " + arg1 + " for the query parameter " + arg2 +
+ " is of a different type than the parameter can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the query parameter in the "
+ "request and resubmit "
+ "the request if the operation failed."}});
}
/**
@@ -654,18 +880,21 @@ nlohmann::json queryParameterValueTypeError(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json serviceShuttingDown()
+void serviceShuttingDown(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ServiceShuttingDown"},
- {"Message",
- "The operation failed because the service is shutting down and can no "
- "longer take incoming requests."},
- {"Severity", "Critical"},
- {"Resolution",
- "When the service becomes available, resubmit the request if the "
- "operation failed."}};
+ res.result(boost::beast::http::status::service_unavailable);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ServiceShuttingDown"},
+ {"Message", "The operation failed because the service is shutting "
+ "down and can no "
+ "longer take incoming requests."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "When the service becomes available, resubmit the request if the "
+ "operation failed."}});
}
/**
@@ -675,20 +904,23 @@ nlohmann::json serviceShuttingDown()
* See header file for more information
* @endinternal
*/
-nlohmann::json actionParameterDuplicate(const std::string& arg1,
- const std::string& arg2)
-{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ActionParameterDuplicate"},
- {"Message",
- "The action " + arg1 +
- " was submitted with more than one value for the parameter " +
- arg2 + "."},
- {"Severity", "Warning"},
- {"Resolution",
- "Resubmit the action with only one instance of the parameter in the "
- "request body if the operation failed."}};
+void actionParameterDuplicate(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ActionParameterDuplicate"},
+ {"Message",
+ "The action " + arg1 +
+ " was submitted with more than one value for the parameter " +
+ arg2 + "."},
+ {"Severity", "Warning"},
+ {"Resolution", "Resubmit the action with only one instance of the "
+ "parameter in the "
+ "request body if the operation failed."}});
}
/**
@@ -698,18 +930,21 @@ nlohmann::json actionParameterDuplicate(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json actionParameterNotSupported(const std::string& arg1,
- const std::string& arg2)
+void actionParameterNotSupported(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ActionParameterNotSupported"},
- {"Message", "The parameter " + arg1 + " for the action " + arg2 +
- " is not supported on the target resource."},
- {"Severity", "Warning"},
- {"Resolution",
- "Remove the parameter supplied and resubmit the request if the "
- "operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ActionParameterNotSupported"},
+ {"Message", "The parameter " + arg1 + " for the action " + arg2 +
+ " is not supported on the target resource."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Remove the parameter supplied and resubmit the request if the "
+ "operation failed."}});
}
/**
@@ -719,17 +954,20 @@ nlohmann::json actionParameterNotSupported(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json sourceDoesNotSupportProtocol(const std::string& arg1,
- const std::string& arg2)
+void sourceDoesNotSupportProtocol(crow::Response& res, const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.SourceDoesNotSupportProtocol"},
- {"Message", "The other end of the Connection at " + arg1 +
- " does not support the specified protocol " + arg2 +
- "."},
- {"Severity", "Critical"},
- {"Resolution", "Change protocols or URIs. "}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.SourceDoesNotSupportProtocol"},
+ {"Message", "The other end of the Connection at " + arg1 +
+ " does not support the specified protocol " + arg2 +
+ "."},
+ {"Severity", "Critical"},
+ {"Resolution", "Change protocols or URIs. "}});
}
/**
@@ -739,14 +977,17 @@ nlohmann::json sourceDoesNotSupportProtocol(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json accountRemoved()
+void accountRemoved(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.AccountRemoved"},
- {"Message", "The account was successfully removed."},
- {"Severity", "OK"},
- {"Resolution", "No resolution is required."}};
+ res.result(boost::beast::http::status::ok);
+ addMessageToJsonRoot(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.AccountRemoved"},
+ {"Message", "The account was successfully removed."},
+ {"Severity", "OK"},
+ {"Resolution", "No resolution is required."}});
}
/**
@@ -756,17 +997,21 @@ nlohmann::json accountRemoved()
* See header file for more information
* @endinternal
*/
-nlohmann::json accessDenied(const std::string& arg1)
+void accessDenied(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.AccessDenied"},
- {"Message", "While attempting to establish a Connection to " + arg1 +
- ", the service denied access."},
- {"Severity", "Critical"},
- {"Resolution", "Attempt to ensure that the URI is correct and that the "
- "service has the "
- "appropriate credentials."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.AccessDenied"},
+ {"Message", "While attempting to establish a Connection to " +
+ arg1 + ", the service denied access."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Attempt to ensure that the URI is correct and that the "
+ "service has the "
+ "appropriate credentials."}});
}
/**
@@ -776,16 +1021,20 @@ nlohmann::json accessDenied(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json queryNotSupported()
+void queryNotSupported(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.QueryNotSupported"},
- {"Message", "Querying is not supported by the implementation."},
- {"Severity", "Warning"},
- {"Resolution", "Remove the query parameters and resubmit the request "
- "if the operation "
- "failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.QueryNotSupported"},
+ {"Message", "Querying is not supported by the implementation."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Remove the query parameters and resubmit the request "
+ "if the operation "
+ "failed."}});
}
/**
@@ -795,18 +1044,21 @@ nlohmann::json queryNotSupported()
* See header file for more information
* @endinternal
*/
-nlohmann::json createLimitReachedForResource()
+void createLimitReachedForResource(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.CreateLimitReachedForResource"},
- {"Message", "The create operation failed because the resource has "
- "reached the limit "
- "of possible resources."},
- {"Severity", "Critical"},
- {"Resolution",
- "Either delete resources and resubmit the request if the operation "
- "failed or do not resubmit the request."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.CreateLimitReachedForResource"},
+ {"Message", "The create operation failed because the resource has "
+ "reached the limit "
+ "of possible resources."},
+ {"Severity", "Critical"},
+ {"Resolution", "Either delete resources and resubmit the request "
+ "if the operation "
+ "failed or do not resubmit the request."}});
}
/**
@@ -816,15 +1068,19 @@ nlohmann::json createLimitReachedForResource()
* See header file for more information
* @endinternal
*/
-nlohmann::json generalError()
+void generalError(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.GeneralError"},
- {"Message", "A general error has occurred. See ExtendedInfo for more "
- "information."},
- {"Severity", "Critical"},
- {"Resolution", "See ExtendedInfo for more information."}};
+ res.result(boost::beast::http::status::internal_server_error);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.GeneralError"},
+ {"Message",
+ "A general error has occurred. See ExtendedInfo for more "
+ "information."},
+ {"Severity", "Critical"},
+ {"Resolution", "See ExtendedInfo for more information."}});
}
/**
@@ -834,14 +1090,38 @@ nlohmann::json generalError()
* See header file for more information
* @endinternal
*/
-nlohmann::json success()
+void success(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.Success"},
- {"Message", "Successfully Completed Request"},
- {"Severity", "OK"},
- {"Resolution", "None"}};
+ res.result(boost::beast::http::status::ok);
+ addMessageToJsonRoot(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.Success"},
+ {"Message", "Successfully Completed Request"},
+ {"Severity", "OK"},
+ {"Resolution", "None"}});
+}
+
+/**
+ * @internal
+ * @brief Formats Success message into JSON for the specified field
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void success(crow::Response& res, const std::string& fieldPath)
+{
+ res.result(boost::beast::http::status::ok);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.Success"},
+ {"Message", "Successfully Completed Request"},
+ {"Severity", "OK"},
+ {"Resolution", "None"}},
+ fieldPath);
}
/**
@@ -851,14 +1131,17 @@ nlohmann::json success()
* See header file for more information
* @endinternal
*/
-nlohmann::json created()
+void created(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.Created"},
- {"Message", "The resource has been created successfully"},
- {"Severity", "OK"},
- {"Resolution", "None"}};
+ res.result(boost::beast::http::status::created);
+ addMessageToJsonRoot(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.Created"},
+ {"Message", "The resource has been created successfully"},
+ {"Severity", "OK"},
+ {"Resolution", "None"}});
}
/**
@@ -868,18 +1151,47 @@ nlohmann::json created()
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyUnknown(const std::string& arg1)
+void propertyUnknown(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyUnknown"},
- {"Message",
- "The property " + arg1 +
- " is not in the list of valid properties for the resource."},
- {"Severity", "Warning"},
- {"Resolution",
- "Remove the unknown property from the request body and resubmit the "
- "request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyUnknown"},
+ {"Message",
+ "The property " + arg1 +
+ " is not in the list of valid properties for the resource."},
+ {"Severity", "Warning"},
+ {"Resolution", "Remove the unknown property from the request body "
+ "and resubmit the "
+ "request if the operation failed."}});
+}
+
+/**
+ * @internal
+ * @brief Formats PropertyUnknown message into JSON for the specified property
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void propertyUnknown(crow::Response& res, const std::string& arg1,
+ const std::string& property)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyUnknown"},
+ {"Message",
+ "The property " + arg1 +
+ " is not in the list of valid properties for the resource."},
+ {"Severity", "Warning"},
+ {"Resolution", "Remove the unknown property from the request body "
+ "and resubmit the "
+ "request if the operation failed."}},
+ property);
}
/**
@@ -889,16 +1201,19 @@ nlohmann::json propertyUnknown(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json noValidSession()
+void noValidSession(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.NoValidSession"},
- {"Message",
- "There is no valid session established with the implementation."},
- {"Severity", "Critical"},
- {"Resolution",
- "Establish as session before attempting any operations."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.NoValidSession"},
+ {"Message",
+ "There is no valid session established with the implementation."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Establish as session before attempting any operations."}});
}
/**
@@ -908,16 +1223,20 @@ nlohmann::json noValidSession()
* See header file for more information
* @endinternal
*/
-nlohmann::json invalidObject(const std::string& arg1)
+void invalidObject(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.InvalidObject"},
- {"Message", "The object at " + arg1 + " is invalid."},
- {"Severity", "Critical"},
- {"Resolution", "Either the object is malformed or the URI is not "
- "correct. Correct the "
- "condition and resubmit the request if it failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.InvalidObject"},
+ {"Message", "The object at " + arg1 + " is invalid."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Either the object is malformed or the URI is not "
+ "correct. Correct the "
+ "condition and resubmit the request if it failed."}});
}
/**
@@ -927,18 +1246,21 @@ nlohmann::json invalidObject(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceInStandby()
+void resourceInStandby(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceInStandby"},
- {"Message",
- "The request could not be performed because the resource is in "
- "standby."},
- {"Severity", "Critical"},
- {"Resolution",
- "Ensure that the resource is in the correct power state and resubmit "
- "the request."}};
+ res.result(boost::beast::http::status::service_unavailable);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceInStandby"},
+ {"Message",
+ "The request could not be performed because the resource is in "
+ "standby."},
+ {"Severity", "Critical"},
+ {"Resolution", "Ensure that the resource is in the correct power "
+ "state and resubmit "
+ "the request."}});
}
/**
@@ -948,21 +1270,24 @@ nlohmann::json resourceInStandby()
* See header file for more information
* @endinternal
*/
-nlohmann::json actionParameterValueTypeError(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3)
-{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ActionParameterValueTypeError"},
- {"Message",
- "The value " + arg1 + " for the parameter " + arg2 +
- " in the action " + arg3 +
- " is of a different type than the parameter can accept."},
- {"Severity", "Warning"},
- {"Resolution",
- "Correct the value for the parameter in the request body and resubmit "
- "the request if the operation failed."}};
+void actionParameterValueTypeError(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string& arg3)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ActionParameterValueTypeError"},
+ {"Message",
+ "The value " + arg1 + " for the parameter " + arg2 +
+ " in the action " + arg3 +
+ " is of a different type than the parameter can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the parameter in the request "
+ "body and resubmit "
+ "the request if the operation failed."}});
}
/**
@@ -972,19 +1297,23 @@ nlohmann::json actionParameterValueTypeError(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json sessionLimitExceeded()
+void sessionLimitExceeded(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.SessionLimitExceeded"},
- {"Message",
- "The session establishment failed due to the number of simultaneous "
- "sessions exceeding the limit of the implementation."},
- {"Severity", "Critical"},
- {"Resolution",
- "Reduce the number of other sessions before trying to establish the "
- "session or increase the limit of simultaneous sessions (if "
- "supported)."}};
+ res.result(boost::beast::http::status::service_unavailable);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.SessionLimitExceeded"},
+ {"Message", "The session establishment failed due to the number of "
+ "simultaneous "
+ "sessions exceeding the limit of the implementation."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Reduce the number of other sessions before trying to establish "
+ "the "
+ "session or increase the limit of simultaneous sessions (if "
+ "supported)."}});
}
/**
@@ -994,18 +1323,23 @@ nlohmann::json sessionLimitExceeded()
* See header file for more information
* @endinternal
*/
-nlohmann::json actionNotSupported(const std::string& arg1)
+void actionNotSupported(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ActionNotSupported"},
- {"Message",
- "The action " + arg1 + " is not supported by the resource."},
- {"Severity", "Critical"},
- {"Resolution",
- "The action supplied cannot be resubmitted to the implementation. "
- "Perhaps the action was invalid, the wrong resource was the target or "
- "the implementation documentation may be of assistance."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ActionNotSupported"},
+ {"Message",
+ "The action " + arg1 + " is not supported by the resource."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "The action supplied cannot be resubmitted to the implementation. "
+ " "
+ "Perhaps the action was invalid, the wrong resource was the "
+ "target or "
+ "the implementation documentation may be of assistance."}});
}
/**
@@ -1015,16 +1349,19 @@ nlohmann::json actionNotSupported(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json invalidIndex(const int& arg1)
+void invalidIndex(crow::Response& res, const int& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.InvalidIndex"},
- {"Message", "The index " + std::to_string(arg1) +
- " is not a valid offset into the array."},
- {"Severity", "Warning"},
- {"Resolution",
- "Verify the index value provided is within the bounds of the array."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.InvalidIndex"},
+ {"Message", "The index " + std::to_string(arg1) +
+ " is not a valid offset into the array."},
+ {"Severity", "Warning"},
+ {"Resolution", "Verify the index value provided is within the "
+ "bounds of the array."}});
}
/**
@@ -1034,17 +1371,20 @@ nlohmann::json invalidIndex(const int& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json emptyJSON()
+void emptyJSON(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.EmptyJSON"},
- {"Message",
- "The request body submitted contained an empty JSON object and the "
- "service is unable to process it."},
- {"Severity", "Warning"},
- {"Resolution",
- "Add properties in the JSON object and resubmit the request."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.EmptyJSON"},
+ {"Message", "The request body submitted contained an empty JSON "
+ "object and the "
+ "service is unable to process it."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Add properties in the JSON object and resubmit the request."}});
}
/**
@@ -1054,16 +1394,20 @@ nlohmann::json emptyJSON()
* See header file for more information
* @endinternal
*/
-nlohmann::json queryNotSupportedOnResource()
+void queryNotSupportedOnResource(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.QueryNotSupportedOnResource"},
- {"Message", "Querying is not supported on the requested resource."},
- {"Severity", "Warning"},
- {"Resolution", "Remove the query parameters and resubmit the request "
- "if the operation "
- "failed."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.QueryNotSupportedOnResource"},
+ {"Message", "Querying is not supported on the requested resource."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Remove the query parameters and resubmit the request "
+ "if the operation "
+ "failed."}});
}
/**
@@ -1073,19 +1417,23 @@ nlohmann::json queryNotSupportedOnResource()
* See header file for more information
* @endinternal
*/
-nlohmann::json insufficientPrivilege()
+void insufficientPrivilege(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.InsufficientPrivilege"},
- {"Message",
- "There are insufficient privileges for the account or credentials "
- "associated with the current session to perform the requested "
- "operation."},
- {"Severity", "Critical"},
- {"Resolution",
- "Either abandon the operation or change the associated access rights "
- "and resubmit the request if the operation failed."}};
+ res.result(boost::beast::http::status::forbidden);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.InsufficientPrivilege"},
+ {"Message",
+ "There are insufficient privileges for the account or credentials "
+ "associated with the current session to perform the requested "
+ "operation."},
+ {"Severity", "Critical"},
+ {"Resolution",
+ "Either abandon the operation or change the associated access "
+ "rights "
+ "and resubmit the request if the operation failed."}});
}
/**
@@ -1095,16 +1443,21 @@ nlohmann::json insufficientPrivilege()
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyValueModified(const std::string& arg1,
- const std::string& arg2)
+void propertyValueModified(crow::Response& res, const std::string& arg1,
+ const std::string& arg2,
+ const std::string& fieldPath)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyValueModified"},
- {"Message", "The property " + arg1 + " was assigned the value " + arg2 +
- " due to modification by the service."},
- {"Severity", "Warning"},
- {"Resolution", "No resolution is required."}};
+ res.result(boost::beast::http::status::ok);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyValueModified"},
+ {"Message", "The property " + arg1 + " was assigned the value " +
+ arg2 + " due to modification by the service."},
+ {"Severity", "Warning"},
+ {"Resolution", "No resolution is required."}},
+ fieldPath);
}
/**
@@ -1114,16 +1467,19 @@ nlohmann::json propertyValueModified(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json accountNotModified()
+void accountNotModified(crow::Response& res)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.AccountNotModified"},
- {"Message", "The account modification request failed."},
- {"Severity", "Warning"},
- {"Resolution",
- "The modification may have failed due to permission issues or issues "
- "with the request body."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.AccountNotModified"},
+ {"Message", "The account modification request failed."},
+ {"Severity", "Warning"},
+ {"Resolution", "The modification may have failed due to permission "
+ "issues or issues "
+ "with the request body."}});
}
/**
@@ -1133,19 +1489,23 @@ nlohmann::json accountNotModified()
* See header file for more information
* @endinternal
*/
-nlohmann::json queryParameterValueFormatError(const std::string& arg1,
- const std::string& arg2)
+void queryParameterValueFormatError(crow::Response& res,
+ const std::string& arg1,
+ const std::string& arg2)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.QueryParameterValueFormatError"},
- {"Message",
- "The value " + arg1 + " for the parameter " + arg2 +
- " is of a different format than the parameter can accept."},
- {"Severity", "Warning"},
- {"Resolution", "Correct the value for the query parameter in the "
- "request and resubmit "
- "the request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.QueryParameterValueFormatError"},
+ {"Message",
+ "The value " + arg1 + " for the parameter " + arg2 +
+ " is of a different format than the parameter can accept."},
+ {"Severity", "Warning"},
+ {"Resolution", "Correct the value for the query parameter in the "
+ "request and resubmit "
+ "the request if the operation failed."}});
}
/**
@@ -1155,18 +1515,49 @@ nlohmann::json queryParameterValueFormatError(const std::string& arg1,
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyMissing(const std::string& arg1)
+void propertyMissing(crow::Response& res, const std::string& arg1)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyMissing"},
+ {"Message", "The property " + arg1 +
+ " is a required property and must be included in "
+ "the request."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Ensure that the property is in the request body and "
+ "has a valid value "
+ "and resubmit the request if the operation failed."}});
+}
+
+/**
+ * @internal
+ * @brief Formats PropertyMissing message into JSON for the specified property
+ *
+ * See header file for more information
+ * @endinternal
+ */
+void propertyMissing(crow::Response& res, const std::string& arg1,
+ const std::string& property)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.PropertyMissing"},
- {"Message",
- "The property " + arg1 +
- " is a required property and must be included in the request."},
- {"Severity", "Warning"},
- {"Resolution", "Ensure that the property is in the request body and "
- "has a valid value "
- "and resubmit the request if the operation failed."}};
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.PropertyMissing"},
+ {"Message", "The property " + arg1 +
+ " is a required property and must be included in "
+ "the request."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Ensure that the property is in the request body and "
+ "has a valid value "
+ "and resubmit the request if the operation failed."}},
+ property);
}
/**
@@ -1176,18 +1567,21 @@ nlohmann::json propertyMissing(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json resourceExhaustion(const std::string& arg1)
+void resourceExhaustion(crow::Response& res, const std::string& arg1)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.ResourceExhaustion"},
- {"Message", "The resource " + arg1 +
- " was unable to satisfy the request "
- "due to unavailability of "
- "resources."},
- {"Severity", "Critical"},
- {"Resolution",
- "Ensure that the resources are available and resubmit the request."}};
+ res.result(boost::beast::http::status::service_unavailable);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.ResourceExhaustion"},
+ {"Message", "The resource " + arg1 +
+ " was unable to satisfy the request "
+ "due to unavailability of "
+ "resources."},
+ {"Severity", "Critical"},
+ {"Resolution", "Ensure that the resources are available and "
+ "resubmit the request."}});
}
/**
@@ -1197,14 +1591,18 @@ nlohmann::json resourceExhaustion(const std::string& arg1)
* See header file for more information
* @endinternal
*/
-nlohmann::json accountModified()
+void accountModified(crow::Response& res, const std::string& fieldPath)
{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.AccountModified"},
- {"Message", "The account was successfully modified."},
- {"Severity", "OK"},
- {"Resolution", "No resolution is required."}};
+ res.result(boost::beast::http::status::ok);
+ addMessageToJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.AccountModified"},
+ {"Message", "The account was successfully modified."},
+ {"Severity", "OK"},
+ {"Resolution", "No resolution is required."}},
+ fieldPath);
}
/**
@@ -1214,27 +1612,27 @@ nlohmann::json accountModified()
* See header file for more information
* @endinternal
*/
-nlohmann::json queryParameterOutOfRange(const std::string& arg1,
- const std::string& arg2,
- const std::string& arg3)
-{
- return nlohmann::json{
- {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
- {"MessageId", "Base.1.2.0.QueryParameterOutOfRange"},
- {"Message", "The value " + arg1 + " for the query parameter " + arg2 +
- " is out of range " + arg3 + "."},
- {"Severity", "Warning"},
- {"Resolution",
- "Reduce the value for the query parameter to a value that is within "
- "range, such as a start or count value that is within bounds of the "
- "number of resources in a collection or a page that is within the "
- "range "
- "of valid pages."}};
-}
-
-/*********************************
- * AUTOGENERATED FUNCTIONS END *
- *********************************/
+void queryParameterOutOfRange(crow::Response& res, const std::string& arg1,
+ const std::string& arg2, const std::string& arg3)
+{
+ res.result(boost::beast::http::status::bad_request);
+ addMessageToErrorJson(
+ res.jsonValue,
+ nlohmann::json{
+ {"@odata.type", "/redfish/v1/$metadata#Message.v1_0_0.Message"},
+ {"MessageId", "Base.1.2.0.QueryParameterOutOfRange"},
+ {"Message", "The value " + arg1 + " for the query parameter " +
+ arg2 + " is out of range " + arg3 + "."},
+ {"Severity", "Warning"},
+ {"Resolution",
+ "Reduce the value for the query parameter to a value that is "
+ "within "
+ "range, such as a start or count value that is within bounds of "
+ "the "
+ "number of resources in a collection or a page that is within the "
+ "range "
+ "of valid pages."}});
+}
} // namespace messages
diff --git a/redfish-core/src/utils/json_utils.cpp b/redfish-core/src/utils/json_utils.cpp
index e14131713a..a47b4d8217 100644
--- a/redfish-core/src/utils/json_utils.cpp
+++ b/redfish-core/src/utils/json_utils.cpp
@@ -21,484 +21,6 @@ namespace redfish
namespace json_util
{
-Result getString(const char* fieldName, const nlohmann::json& json,
- const std::string*& output)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- return Result::NOT_EXIST;
- }
-
- output = fieldIt->get_ptr<const std::string*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (output == nullptr)
- {
- return Result::WRONG_TYPE;
- }
-
- return Result::SUCCESS;
-}
-
-Result getObject(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output)
-{
- // Verify input pointer
- if (output == nullptr)
- {
- return Result::NULL_POINTER;
- }
-
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- return Result::NOT_EXIST;
- }
-
- // Verify type
- if (!fieldIt->is_object())
- {
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- *output = *fieldIt;
-
- return Result::SUCCESS;
-}
-
-Result getArray(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output)
-{
- // Verify input pointer
- if (output == nullptr)
- {
- return Result::NULL_POINTER;
- }
-
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- return Result::NOT_EXIST;
- }
-
- // Verify type
- if (!fieldIt->is_array())
- {
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- *output = *fieldIt;
-
- return Result::SUCCESS;
-}
-
-Result getInt(const char* fieldName, const nlohmann::json& json,
- int64_t& output)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- return Result::NOT_EXIST;
- }
-
- const int64_t* retVal = fieldIt->get_ptr<const int64_t*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
-Result getUnsigned(const char* fieldName, const nlohmann::json& json,
- uint64_t& output)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- return Result::NOT_EXIST;
- }
-
- const uint64_t* retVal = fieldIt->get_ptr<const uint64_t*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
-Result getBool(const char* fieldName, const nlohmann::json& json, bool& output)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- return Result::NOT_EXIST;
- }
-
- const bool* retVal = fieldIt->get_ptr<const bool*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
-Result getDouble(const char* fieldName, const nlohmann::json& json,
- double& output)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- return Result::NOT_EXIST;
- }
-
- const double* retVal = fieldIt->get_ptr<const double*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
-Result getString(const char* fieldName, const nlohmann::json& json,
- const std::string*& output, uint8_t msgCfgMap,
- nlohmann::json& msgJson, const std::string&& fieldPath)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::MISSING))
- {
- messages::addMessageToJson(
- msgJson, messages::propertyMissing(fieldName), fieldPath);
- }
-
- return Result::NOT_EXIST;
- }
-
- output = fieldIt->get_ptr<const std::string*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (output == nullptr)
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::TYPE_ERROR))
- {
- messages::addMessageToJson(
- msgJson,
- messages::propertyValueTypeError(fieldIt->dump(), fieldName),
- fieldPath);
- }
-
- return Result::WRONG_TYPE;
- }
-
- return Result::SUCCESS;
-}
-
-Result getObject(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output, uint8_t msgCfgMap,
- nlohmann::json& msgJson, const std::string&& fieldPath)
-{
- // Verify input pointer
- if (output == nullptr)
- {
- return Result::NULL_POINTER;
- }
-
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::MISSING))
- {
- messages::addMessageToJson(
- msgJson, messages::propertyMissing(fieldName), fieldPath);
- }
-
- return Result::NOT_EXIST;
- }
-
- // Verify type
- if (!fieldIt->is_object())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::TYPE_ERROR))
- {
- messages::addMessageToJson(
- msgJson,
- messages::propertyValueTypeError(fieldIt->dump(), fieldName),
- fieldPath);
- }
-
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- *output = *fieldIt;
-
- return Result::SUCCESS;
-}
-
-Result getArray(const char* fieldName, const nlohmann::json& json,
- nlohmann::json* output, uint8_t msgCfgMap,
- nlohmann::json& msgJson, const std::string&& fieldPath)
-{
- // Verify input pointer
- if (output == nullptr)
- {
- return Result::NULL_POINTER;
- }
-
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::MISSING))
- {
- messages::addMessageToJson(
- msgJson, messages::propertyMissing(fieldName), fieldPath);
- }
-
- return Result::NOT_EXIST;
- }
-
- // Verify type
- if (!fieldIt->is_array())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::TYPE_ERROR))
- {
- messages::addMessageToJson(
- msgJson,
- messages::propertyValueTypeError(fieldIt->dump(), fieldName),
- fieldPath);
- }
-
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- *output = *fieldIt;
-
- return Result::SUCCESS;
-}
-
-Result getInt(const char* fieldName, const nlohmann::json& json,
- int64_t& output, uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::MISSING))
- {
- messages::addMessageToJson(
- msgJson, messages::propertyMissing(fieldName), fieldPath);
- }
-
- return Result::NOT_EXIST;
- }
-
- const int64_t* retVal = fieldIt->get_ptr<const int64_t*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::TYPE_ERROR))
- {
- messages::addMessageToJson(
- msgJson,
- messages::propertyValueTypeError(fieldIt->dump(), fieldName),
- fieldPath);
- }
-
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
-Result getUnsigned(const char* fieldName, const nlohmann::json& json,
- uint64_t& output, uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::MISSING))
- {
- messages::addMessageToJson(
- msgJson, messages::propertyMissing(fieldName), fieldPath);
- }
-
- return Result::NOT_EXIST;
- }
-
- const uint64_t* retVal = fieldIt->get_ptr<const uint64_t*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::TYPE_ERROR))
- {
- messages::addMessageToJson(
- msgJson,
- messages::propertyValueTypeError(fieldIt->dump(), fieldName),
- fieldPath);
- }
-
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
-Result getBool(const char* fieldName, const nlohmann::json& json, bool& output,
- uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::MISSING))
- {
- messages::addMessageToJson(
- msgJson, messages::propertyMissing(fieldName), fieldPath);
- }
-
- return Result::NOT_EXIST;
- }
-
- const bool* retVal = fieldIt->get_ptr<const bool*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::TYPE_ERROR))
- {
- messages::addMessageToJson(
- msgJson,
- messages::propertyValueTypeError(fieldIt->dump(), fieldName),
- fieldPath);
- }
-
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
-Result getDouble(const char* fieldName, const nlohmann::json& json,
- double& output, uint8_t msgCfgMap, nlohmann::json& msgJson,
- const std::string&& fieldPath)
-{
- // Find field
- auto fieldIt = json.find(fieldName);
-
- // Verify existence
- if (fieldIt == json.end())
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::MISSING))
- {
- messages::addMessageToJson(
- msgJson, messages::propertyMissing(fieldName), fieldPath);
- }
-
- return Result::NOT_EXIST;
- }
-
- const double* retVal = fieldIt->get_ptr<const double*>();
-
- // Verify type - we know that it exists, so nullptr means wrong type
- if (retVal == nullptr)
- {
- if (msgCfgMap & static_cast<int>(MessageSetting::TYPE_ERROR))
- {
- messages::addMessageToJson(
- msgJson,
- messages::propertyValueTypeError(fieldIt->dump(), fieldName),
- fieldPath);
- }
-
- return Result::WRONG_TYPE;
- }
-
- // Extract value
- output = *retVal;
-
- return Result::SUCCESS;
-}
-
bool processJsonFromRequest(crow::Response& res, const crow::Request& req,
nlohmann::json& reqJson)
{
@@ -506,10 +28,8 @@ bool processJsonFromRequest(crow::Response& res, const crow::Request& req,
if (reqJson.is_discarded())
{
- messages::addMessageToErrorJson(res.jsonValue,
- messages::malformedJSON());
+ messages::malformedJSON(res);
- res.result(boost::beast::http::status::bad_request);
res.end();
return false;