| 84 | } |
| 85 | |
| 86 | void 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. |
nothing calls this directly
no test coverage detected