mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 05:34:48 +02:00
Add HttpUtility::SendJsonError() overload for Boost/Beast
This commit is contained in:
parent
fc22cbaf09
commit
04a9879acc
@ -103,6 +103,24 @@ void HttpUtility::SendJsonError(HttpResponse& response, const Dictionary::Ptr& p
|
|||||||
HttpUtility::SendJsonBody(response, params, result);
|
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)
|
String HttpUtility::GetErrorNameByCode(const int code)
|
||||||
{
|
{
|
||||||
switch(code) {
|
switch(code) {
|
||||||
|
@ -26,6 +26,8 @@ public:
|
|||||||
static Value GetLastParameter(const Dictionary::Ptr& params, const String& key);
|
static Value GetLastParameter(const Dictionary::Ptr& params, const String& key);
|
||||||
static void SendJsonError(HttpResponse& response, const Dictionary::Ptr& params, const int code,
|
static void SendJsonError(HttpResponse& response, const Dictionary::Ptr& params, const int code,
|
||||||
const String& verbose = String(), const String& diagnosticInformation = String());
|
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:
|
private:
|
||||||
static String GetErrorNameByCode(int code);
|
static String GetErrorNameByCode(int code);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user