fix: remove dead .status assignment and add 503 error test

This commit is contained in:
Saurabh
2026-03-26 20:43:45 +05:30
committed by Peter Steinberger
parent 517ae6ea14
commit 8ab6891d97
2 changed files with 26 additions and 3 deletions

View File

@@ -499,6 +499,31 @@ describe("createOllamaStreamFn", () => {
);
});
it("surfaces non-2xx HTTP response as status-prefixed error", async () => {
const originalFetch = globalThis.fetch;
const fetchMock = vi.fn(async () => {
return new Response("Service Unavailable", {
status: 503,
statusText: "Service Unavailable",
});
});
globalThis.fetch = fetchMock as unknown as typeof fetch;
try {
const stream = await createOllamaTestStream({ baseUrl: "http://ollama-host:11434" });
const events = await collectStreamEvents(stream);
const errorEvent = events.find((e) => e.type === "error") as
| { type: "error"; error: { errorMessage?: string } }
| undefined;
expect(errorEvent).toBeDefined();
// The error message must start with the HTTP status code so that
// extractLeadingHttpStatus can parse it for failover/retry logic.
expect(errorEvent!.error.errorMessage).toMatch(/^503\b/);
} finally {
globalThis.fetch = originalFetch;
}
});
it("drops thinking chunks when no final content is emitted", async () => {
await expectDoneEventContent(
[

View File

@@ -488,9 +488,7 @@ export function createOllamaStreamFn(
if (!response.ok) {
const errorText = await response.text().catch(() => "unknown error");
const err = new Error(`${response.status} ${errorText}`);
(err as Error & { status: number }).status = response.status;
throw err;
throw new Error(`${response.status} ${errorText}`);
}
if (!response.body) {