MCPcopy Create free account
hub / github.com/Icinga/icinga2 / SendJsonError

Method SendJsonError

lib/remote/httputility.cpp:86–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84}
85
86void HttpUtility::SendJsonError(HttpApiResponse& response,
87 const Dictionary::Ptr& params, int code, const String& info, const String& diagnosticInformation)
88{
89 if (response.HasSerializationStarted()) {
90 std::ostringstream err;
91 err << "Impossible to send error response after streaming has started: error: '" << code << "', status: '"
92 << info << "'";
93 if (!diagnosticInformation.IsEmpty()) {
94 err << ", diagnostic_information: '" << diagnosticInformation << "'";
95 }
96 BOOST_THROW_EXCEPTION(std::logic_error{err.str()});
97 }
98
99 Dictionary::Ptr result = new Dictionary({ { "error", code } });
100
101 if (!info.IsEmpty()) {
102 result->Set("status", info);
103 }
104
105 if (params && HttpUtility::GetLastParameter(params, "verbose") && !diagnosticInformation.IsEmpty()) {
106 result->Set("diagnostic_information", diagnosticInformation);
107 }
108
109 response.Clear();
110 response.result(code);
111
112 HttpUtility::SendJsonBody(response, params, result);
113}
114
115/**
116 * Check if the given string is suitable to be used as an HTTP header name.

Callers

nothing calls this directly

Calls 4

IsEmptyMethod · 0.45
SetMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected