import { afterEach, describe, expect, test } from "bun:test"; import { createSealClientForUrl } from "./factory.js"; const servers: Array> = []; afterEach(() => { for (const server of servers.splice(0)) server.stop(true); }); describe("Seal HTTP client errors", () => { test("includes ky's parsed response body after the response stream is consumed", async () => { const server = Bun.serve({ port: 0, fetch: () => new Response(JSON.stringify({ error: { code: "error:common:invalid-parameter", message: "contentType 取值非法" } }), { status: 400, headers: { "content-type": "application/json" } }) }); servers.push(server); await expect( createSealClientForUrl(`http://127.0.0.1:${server.port}`, "dummy-token").get("/") ).rejects.toThrow( 'Request failed with status code 400 Bad Request: GET http://127.0.0.1:' + `${server.port}/: {"error":{"code":"error:common:invalid-parameter","message":"contentType 取值非法"}}` ); }); });