Guard against assert() failures in SendJsonError()

Co-authored-by: Julian Brost <julian.brost@icinga.com>
This commit is contained in:
Johannes Schmidt 2026-06-02 10:19:02 +02:00
parent 6a3979fd1f
commit fe469a5455

View file

@ -86,6 +86,16 @@ void HttpUtility::SendJsonBody(HttpApiResponse& response, const Dictionary::Ptr&
void HttpUtility::SendJsonError(HttpApiResponse& response,
const Dictionary::Ptr& params, int code, const String& info, const String& diagnosticInformation)
{
if (response.HasSerializationStarted()) {
std::ostringstream err;
err << "Impossible to send error response after streaming has started: error: '" << code << "', status: '"
<< info << "'";
if (!diagnosticInformation.IsEmpty()) {
err << ", diagnostic_information: '" << diagnosticInformation << "'";
}
BOOST_THROW_EXCEPTION(std::logic_error{err.str()});
}
Dictionary::Ptr result = new Dictionary({ { "error", code } });
if (!info.IsEmpty()) {