From 647331de28fc27052aa530b4e6d89ff3beb4ec11 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 18 Dec 2025 00:47:36 -0500 Subject: [PATCH] zen: error handling for stream requests --- .../app/src/routes/zen/util/handler.ts | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/packages/console/app/src/routes/zen/util/handler.ts b/packages/console/app/src/routes/zen/util/handler.ts index 9614f6739..357ffd12c 100644 --- a/packages/console/app/src/routes/zen/util/handler.ts +++ b/packages/console/app/src/routes/zen/util/handler.ts @@ -143,6 +143,9 @@ export async function handler( // Store sticky provider await stickyTracker?.set(providerInfo.id) + // Temporarily change 404 to 400 status code b/c solid start automatically override 404 response + const resStatus = res.status === 404 ? 400 : res.status + // Scrub response headers const resHeaders = new Headers() const keepHeaders = ["content-type", "cache-control"] @@ -153,7 +156,7 @@ export async function handler( } logger.debug("STATUS: " + res.status + " " + res.statusText) - // Handle non-streaming response for non-stream request + // Handle non-streaming response if (!isStream) { const responseConverter = createResponseConverter(providerInfo.format, opts.format) const json = await res.json() @@ -168,23 +171,7 @@ export async function handler( await trackUsage(authInfo, modelInfo, providerInfo, tokensInfo) await reload(authInfo) return new Response(body, { - status: res.status, - statusText: res.statusText, - headers: resHeaders, - }) - } - - // Handle non-streaming response for stream request - const contentType = res.headers.get("content-type") ?? "" - if (!contentType.includes("text/event-stream")) { - const body = await res.text() - logger.metric({ response_length: body.length }) - logger.debug("RESPONSE: " + body) - dataDumper?.provideResponse(body) - dataDumper?.flush() - await rateLimiter?.track() - return new Response(body, { - status: res.status, + status: resStatus, statusText: res.statusText, headers: resHeaders, }) @@ -262,7 +249,7 @@ export async function handler( }) return new Response(stream, { - status: res.status, + status: resStatus, statusText: res.statusText, headers: resHeaders, })