Download backend/tests/stream-errors.test.ts from HuggingFaceSwarms/scaling-swarms: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/spaces/HuggingFaceSwarms/scaling-swarms/resolve/main/backend/tests/stream-errors.test.ts
- Command line
-
hf download hf://spaces/HuggingFaceSwarms/scaling-swarms/backend/tests/stream-errors.test.ts
-
curl -L -o stream-errors.test.ts https://huggingface.co/spaces/HuggingFaceSwarms/scaling-swarms/resolve/main/backend/tests/stream-errors.test.ts
1.41 kB
| import { describe, it, expect } from "vitest"; | |
| import { formatStreamError } from "../src/agent/stream-errors.js"; | |
| describe("formatStreamError", () => { | |
| it("prefixes provider errors with their HTTP status", () => { | |
| const err = Object.assign(new Error("Payment Required"), { statusCode: 402 }); | |
| expect(formatStreamError(err)).toBe("HTTP 402: Payment Required"); | |
| }); | |
| it("prefers the human message from a JSON response body", () => { | |
| const err = Object.assign(new Error("Bad"), { | |
| statusCode: 402, | |
| responseBody: JSON.stringify({ error: "You have exceeded your monthly included credits for Inference Providers." }), | |
| }); | |
| expect(formatStreamError(err)).toBe( | |
| "HTTP 402: You have exceeded your monthly included credits for Inference Providers.", | |
| ); | |
| }); | |
| it("reads nested { error: { message } } bodies and the status of a wrapped cause", () => { | |
| const cause = Object.assign(new Error("x"), { | |
| statusCode: 429, | |
| responseBody: JSON.stringify({ error: { message: "Rate limit reached" } }), | |
| }); | |
| const err = Object.assign(new Error("Rate limit reached"), { cause }); | |
| expect(formatStreamError(err)).toBe("HTTP 429: Rate limit reached"); | |
| }); | |
| it("keeps plain errors unchanged", () => { | |
| expect(formatStreamError(new Error("socket hang up"))).toBe("socket hang up"); | |
| expect(formatStreamError(undefined)).toBe("Stream error"); | |
| }); | |
| }); | |