mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-24 07:31:44 +00:00
fix: remove dead .status assignment and add 503 error test
This commit is contained in:
committed by
Peter Steinberger
parent
517ae6ea14
commit
8ab6891d97
@@ -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(
|
||||
[
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user