]> granicus.if.org Git - icinga2/commitdiff
Add HttpUtility::SendJsonError() overload for Boost/Beast
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Thu, 14 Feb 2019 15:07:06 +0000 (16:07 +0100)
committerAlexander A. Klimov <alexander.klimov@icinga.com>
Mon, 1 Apr 2019 09:40:14 +0000 (11:40 +0200)
lib/remote/httputility.cpp
lib/remote/httputility.hpp

index f7fef77139524335cc4dc758b54b785f45126c19..fa54d9c8945b16d6864e8d0a31822b97db4de38f 100644 (file)
@@ -103,6 +103,24 @@ void HttpUtility::SendJsonError(HttpResponse& response, const Dictionary::Ptr& p
        HttpUtility::SendJsonBody(response, params, result);
 }
 
+void HttpUtility::SendJsonError(boost::beast::http::response<boost::beast::http::string_body>& response,
+       const Dictionary::Ptr& params, int code, const String& info, const String& diagnosticInformation)
+{
+       Dictionary::Ptr result = new Dictionary({ { "error", code } });
+
+       if (!info.IsEmpty()) {
+               result->Set("status", info);
+       }
+
+       if (params && HttpUtility::GetLastParameter(params, "verbose") && !diagnosticInformation.IsEmpty()) {
+               result->Set("diagnostic_information", diagnosticInformation);
+       }
+
+       response.result(code);
+
+       HttpUtility::SendJsonBody(response, params, result);
+}
+
 String HttpUtility::GetErrorNameByCode(const int code)
 {
        switch(code) {
index e758b2663ea3974b32ec50509f0100e0f2522319..7122e3e7167137d063ded0028b986dd5434ba3ec 100644 (file)
@@ -26,6 +26,8 @@ public:
        static Value GetLastParameter(const Dictionary::Ptr& params, const String& key);
        static void SendJsonError(HttpResponse& response, const Dictionary::Ptr& params, const int code,
                const String& verbose = String(), const String& diagnosticInformation = String());
+       static void SendJsonError(boost::beast::http::response<boost::beast::http::string_body>& response, const Dictionary::Ptr& params, const int code,
+               const String& verbose = String(), const String& diagnosticInformation = String());
 
 private:
        static String GetErrorNameByCode(int code);