From ae6883136bfb536788ac88cfa71e3d83865a362b Mon Sep 17 00:00:00 2001 From: Nan Zhou Date: Tue, 16 Aug 2022 01:07:28 +0000 Subject: error message: add insufficientStorage In the spec, when a response is too large, we need a error messsage to represent such error. The corresponding error is 507 Insufficient Storage, which is already in the base registry. This commit adds that utility to error messages library. Reference: redfish spec Section 7.3.2 ``` If a service cannot return the payload due to its size, it shall return the HTTP 507 Insufficient Storage status code. ``` Tested: code compies. Signed-off-by: Nan Zhou Change-Id: I1fe840f015b3d67fa2092d1d3a1f8c3fcbc2c438 --- redfish-core/include/error_messages.hpp | 9 +++++++++ redfish-core/src/error_messages.cpp | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/redfish-core/include/error_messages.hpp b/redfish-core/include/error_messages.hpp index d9f571c76b..1a5b94132d 100644 --- a/redfish-core/include/error_messages.hpp +++ b/redfish-core/include/error_messages.hpp @@ -1018,6 +1018,15 @@ nlohmann::json invalidUpload(std::string_view arg1, std::string_view arg2); void invalidUpload(crow::Response& res, std::string_view arg1, std::string_view arg2); +/** + * @brief Formats InsufficientStorage message into JSON + * Message body: "Insufficent storage or memory available to complete the + * request." + * @returns Message InsufficientStorage formatted to JSON */ +nlohmann::json insufficientStorage(); + +void insufficientStorage(crow::Response& res); + } // namespace messages } // namespace redfish diff --git a/redfish-core/src/error_messages.cpp b/redfish-core/src/error_messages.cpp index cdaced6246..654353d783 100644 --- a/redfish-core/src/error_messages.cpp +++ b/redfish-core/src/error_messages.cpp @@ -1671,6 +1671,24 @@ void invalidUpload(crow::Response& res, std::string_view arg1, addMessageToErrorJson(res.jsonValue, invalidUpload(arg1, arg2)); } +/** + * @internal + * @brief Formats InsufficientStorage message into JSON + * + * See header file for more information + * @endinternal + */ +nlohmann::json insufficientStorage() +{ + return getLog(redfish::registries::base::Index::insufficientStorage, {}); +} + +void insufficientStorage(crow::Response& res) +{ + res.result(boost::beast::http::status::insufficient_storage); + addMessageToErrorJson(res.jsonValue, insufficientStorage()); +} + /** * @internal * @brief Formats Invalid File message into JSON @@ -1693,6 +1711,7 @@ nlohmann::json invalidUpload(std::string_view arg1, std::string_view arg2) {"MessageSeverity", "Warning"}, {"Resolution", "None."}}; } + } // namespace messages } // namespace redfish -- cgit v1.2.3