Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit f7194f3

Browse files
committed
fix: improve error handling for remote engine
1 parent d624f30 commit f7194f3

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

engine/extensions/remote-engine/remote_engine.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ size_t StreamWriteCallback(char* ptr, size_t size, size_t nmemb,
3030
Json::Value check_error;
3131
Json::Reader reader;
3232
context->chunks += chunk;
33-
if (reader.parse(context->chunks, check_error) ||
34-
(reader.parse(chunk, check_error) &&
35-
chunk.find("error") != std::string::npos)) {
33+
34+
long http_code = k200OK;
35+
if (context->curl) {
36+
curl_easy_getinfo(context->curl, CURLINFO_RESPONSE_CODE, &http_code);
37+
}
38+
if (http_code != k200OK && (reader.parse(context->chunks, check_error) ||
39+
(chunk.find("error") != std::string::npos &&
40+
reader.parse(chunk, check_error)))) {
3641
CTL_WRN(context->chunks);
37-
CTL_WRN(chunk);
42+
CTL_WRN("http code: " << http_code << " - " << chunk);
3843
CTL_INF("Request: " << context->last_request);
3944
Json::Value status;
4045
status["is_done"] = true;
@@ -139,7 +144,9 @@ CurlResponse RemoteEngine::MakeStreamingChatCompletionRequest(
139144
renderer_,
140145
stream_template,
141146
true,
142-
body};
147+
body,
148+
"",
149+
curl};
143150

144151
curl_easy_setopt(curl, CURLOPT_URL, full_url.c_str());
145152
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

engine/extensions/remote-engine/remote_engine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct StreamContext {
2727
bool need_stop = true;
2828
std::string last_request;
2929
std::string chunks;
30+
CURL* curl;
3031
};
3132
struct CurlResponse {
3233
std::string body;

0 commit comments

Comments
 (0)