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

123456789101112131415161718192021222324
  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. provider: null,
  13. } as any;
  14. const res = await ProxyErrorHandler.handle(session, new Error("boom"));
  15. expect(res.status).toBe(500);
  16. expect(res.headers.get("x-cch-session-id")).toBe("s_123");
  17. const body = await res.json();
  18. expect(body.error.message).toBe("boom (cch_session_id: s_123)");
  19. });
  20. });