diff options
author | Jason M. Bills <jason.m.bills@linux.intel.com> | 2018-10-09 22:45:45 +0300 |
---|---|---|
committer | Jason M. Bills <jason.m.bills@linux.intel.com> | 2018-10-23 03:00:16 +0300 |
commit | f12894f8bd7fc26ffa16e5a89072e6c19095f866 (patch) | |
tree | e2e2e1629f80a29efca04bd9714525465575549e /redfish-core/lib/redfish_sessions.hpp | |
parent | 9712f8ac42746e65f32c2bc3de0835846652568e (diff) | |
download | bmcweb-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>
Diffstat (limited to 'redfish-core/lib/redfish_sessions.hpp')
-rw-r--r-- | redfish-core/lib/redfish_sessions.hpp | 33 |
1 files changed, 7 insertions, 26 deletions
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; |