update: sync local changes with latest features
This commit is contained in:
@@ -132,7 +132,7 @@ export function translateNonStreamingResponse(responseBody, targetFormat, source
|
||||
/**
|
||||
* Handle non-streaming response from provider.
|
||||
*/
|
||||
export async function handleNonStreamingResponse({ providerResponse, provider, model, sourceFormat, targetFormat, body, stream, translatedBody, finalBody, requestStartTime, connectionId, apiKey, clientRawRequest, onRequestSuccess, reqLogger, toolNameMap, trackDone, appendLog }) {
|
||||
export async function handleNonStreamingResponse({ providerResponse, provider, model, sourceFormat, targetFormat, body, stream, translatedBody, finalBody, requestStartTime, connectionId, apiKey, clientRawRequest, onRequestSuccess, reqLogger, toolNameMap, trackDone, appendLog, midStreamError, onMidStreamError }) {
|
||||
trackDone();
|
||||
const contentType = providerResponse.headers.get("content-type") || "";
|
||||
let responseBody;
|
||||
@@ -144,6 +144,21 @@ export async function handleNonStreamingResponse({ providerResponse, provider, m
|
||||
appendLog({ status: `FAILED ${HTTP_STATUS.BAD_GATEWAY}` });
|
||||
return createErrorResult(HTTP_STATUS.BAD_GATEWAY, "Invalid SSE response for non-streaming request");
|
||||
}
|
||||
|
||||
// Check for mid-stream errors detected during SSE parsing (e.g. Qoder quota exceeded).
|
||||
// The upstream returned HTTP 200 but the SSE envelope contained a non-200 statusCodeValue.
|
||||
// Without this check, the error message would be silently served as normal content with HTTP 200.
|
||||
if (midStreamError?.error) {
|
||||
const err = midStreamError.error;
|
||||
if (typeof onMidStreamError === "function") {
|
||||
onMidStreamError(err).catch(e => {
|
||||
console.error("[MidStreamError] Failed to apply cooldown:", e.message);
|
||||
});
|
||||
}
|
||||
appendLog({ status: `FAILED ${err.status || 429}` });
|
||||
return createErrorResult(err.status || 429, err.message || "Upstream error detected in SSE stream");
|
||||
}
|
||||
|
||||
responseBody = parsed;
|
||||
} else {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user