MCPcopy Create free account
hub / github.com/TelegramMessenger/cocoon / return_error_str

Method return_error_str

runners/client/ClientRunningRequest.cpp:168–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166}
167
168void ClientRunningRequest::return_error_str(td::int32 ton_error_code, std::string error,
169 ton::tl_object_ptr<cocoon_api::client_queryFinalInfo> final_info) {
170 LOG(WARNING) << "client request " << request_id_.to_hex() << ": sending error: " << error;
171 CHECK(!answer_sent_);
172
173 td::int32 error_code;
174 std::string error_string;
175 switch (ton_error_code) {
176 case ton::ErrorCode::timeout:
177 error_code = ton::http::HttpStatusCode::status_gateway_timeout;
178 error_string = "Gateway Timeout";
179 break;
180 case ton::ErrorCode::notready:
181 error_code = ton::http::HttpStatusCode::status_bad_gateway;
182 error_string = "Bad Gateway";
183 break;
184 case ton::ErrorCode::protoviolation:
185 error_code = ton::http::HttpStatusCode::status_bad_request;
186 error_string = "Bad Request";
187 break;
188 default:
189 error_code = ton::http::HttpStatusCode::status_internal_server_error;
190 error_string = "Internal Server Error";
191 break;
192 }
193
194 td::StringBuilder sb;
195 nlohmann::json v = nlohmann::json::object();
196 v["error_code"] = ton_error_code;
197 v["error"] = error;
198 if (final_info && final_info->proxy_debug_.size() > 0) {
199 v["proxy"] = nlohmann::json::parse(final_info->proxy_debug_);
200 }
201 if (final_info && final_info->worker_debug_.size() > 0) {
202 v["worker"] = nlohmann::json::parse(final_info->worker_debug_);
203 }
204 if (enable_debug_) {
205 v["client"] = generate_client_debug_inner();
206 }
207 sb << v.dump();
208
209 auto data = sb.as_cslice();
210
211 callback_->receive_answer(error_code, "application/json", {}, data.str(), false);
212 answer_sent_ = true;
213
214 finish_request(false, std::move(final_info));
215}
216
217void ClientRunningRequest::finish_request(bool is_success,
218 ton::tl_object_ptr<cocoon_api::client_queryFinalInfo> final_info) {

Callers

nothing calls this directly

Calls 3

parseFunction · 0.85
as_csliceMethod · 0.80
receive_answerMethod · 0.45

Tested by

no test coverage detected