Joseph Reynolds | 8fd315a | 2019-09-12 12:02:33 -0500 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include "crow/http_response.h" |
| 4 | |
| 5 | namespace crow |
| 6 | { |
| 7 | namespace msg |
| 8 | { |
| 9 | const std::string notFoundMsg = "404 Not Found"; |
| 10 | const std::string badReqMsg = "400 Bad Request"; |
| 11 | const std::string methodNotAllowedMsg = "405 Method Not Allowed"; |
| 12 | const std::string forbiddenMsg = "403 Forbidden"; |
| 13 | const std::string methodFailedMsg = "500 Method Call Failed"; |
| 14 | const std::string methodOutputFailedMsg = "500 Method Output Error"; |
| 15 | const std::string unAuthMsg = "401 Unauthorized"; // Unauthenticated |
| 16 | |
| 17 | const std::string notFoundDesc = |
| 18 | "org.freedesktop.DBus.Error.FileNotFound: path or object not found"; |
| 19 | const std::string propNotFoundDesc = "The specified property cannot be found"; |
| 20 | const std::string noJsonDesc = "No JSON object could be decoded"; |
| 21 | const std::string methodNotFoundDesc = "The specified method cannot be found"; |
| 22 | const std::string methodNotAllowedDesc = "Method not allowed"; |
| 23 | const std::string forbiddenPropDesc = |
| 24 | "The specified property cannot be created"; |
| 25 | const std::string forbiddenResDesc = "The specified resource cannot be created"; |
| 26 | const std::string unAuthDesc = "The authentication could not be applied"; |
| 27 | const std::string forbiddenURIDesc = "The session is not authorized to access URI: "; |
| 28 | |
| 29 | } // namespace msg |
| 30 | |
| 31 | inline void setErrorResponse(crow::Response &res, |
| 32 | boost::beast::http::status result, |
| 33 | const std::string &desc, const std::string &msg) |
| 34 | { |
| 35 | res.result(result); |
| 36 | res.jsonValue = {{"data", {{"description", desc}}}, |
| 37 | {"message", msg}, |
| 38 | {"status", "error"}}; |
| 39 | } |
| 40 | |
| 41 | inline void setPasswordChangeRequired(crow::Response &res, |
| 42 | const std::string &username) |
| 43 | { |
| 44 | res.jsonValue["extendedMessage"] = |
| 45 | "The password for this account must be changed. PATCH the 'Password' " |
| 46 | "property for the account under URI: " |
| 47 | "/redfish/v1/AccountService/Accounts/" + |
| 48 | username; |
| 49 | } |
| 50 | |
| 51 | } // namespace crow |