error-handler-session-id-error.test.ts 858 B

12345678910111213141516171819202122232425
  1. import { describe, expect, test } from "vitest";
  2. import { ProxyErrorHandler } from "@/app/v1/_lib/proxy/error-handler";
  3. describe("ProxyErrorHandler.handle - session id on errors", () => {
  4. test("decorates error response with x-cch-session-id and message suffix", async () => {
  5. const session = {
  6. sessionId: "s_123",
  7. messageContext: null,
  8. startTime: Date.now(),
  9. getProviderChain: () => [],
  10. getCurrentModel: () => null,
  11. getContext1mApplied: () => false,
  12. getGroupCostMultiplier: () => 1,
  13. provider: null,
  14. } as any;
  15. const res = await ProxyErrorHandler.handle(session, new Error("boom"));
  16. expect(res.status).toBe(500);
  17. expect(res.headers.get("x-cch-session-id")).toBe("s_123");
  18. const body = await res.json();
  19. expect(body.error.message).toBe("boom (cch_session_id: s_123)");
  20. });
  21. });