import { beforeEach, describe, expect, it, vi } from "vitest"; const { captureExceptionMock, captureMessageMock, revalidatePathMock } = vi.hoisted(() => ({ captureExceptionMock: vi.fn(), captureMessageMock: vi.fn(), revalidatePathMock: vi.fn(), })); vi.mock("@sentry/nextjs", () => ({ captureException: captureExceptionMock, captureMessage: captureMessageMock, })); vi.mock("next/cache", () => ({ revalidatePath: revalidatePathMock, })); vi.mock("./helper", () => ({ GENERIC_SERVER_ERROR_MESSAGE: "Server is temporarily unavailable. Please try again in a few minutes.", getErrorMessage: (error: unknown) => error instanceof Error ? error.message : String(error), parseStringify: (value: unknown) => value, sanitizeErrorMessage: (message: string, fallback: string) => / { beforeEach(() => { vi.clearAllMocks(); vi.spyOn(console, "error").mockImplementation(() => {}); }); it("throws a generic server error instead of raw HTML for 5xx responses", async () => { // Given const response = new Response( "502 Bad Gateway

502 Bad Gateway

", { status: 502, statusText: "Bad Gateway", headers: { "content-type": "text/html" }, }, ); // When / Then const result = handleApiResponse(response); await expect(result).rejects.toThrow( "Server is temporarily unavailable. Please try again in a few minutes.", ); }); });