The repo's first frontend test setup: Vitest, React Testing Library, jsdom. Scoped to the flows that lose money or leak data when broken, per spec 4. lib/api.ts collapses every failure into three the UI can act on: NotConnected (unreachable, or no URL baked in), ApiError 401 (redirect), and ApiError with the backend's own message, which is customer-facing and shown verbatim rather than replaced with something vaguer. The not-connected panel names the variable, the value baked in, and both reasons it fails -- unreachable from the browser, or missing from admin's ADMIN_ORIGIN. Proven by test before it existed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
17 lines
509 B
TypeScript
17 lines
509 B
TypeScript
"use client";
|
|
|
|
import { QueryClient } from "@tanstack/react-query";
|
|
import { ApiError, NotConnected } from "./api";
|
|
|
|
export const queryClient = new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
staleTime: 30_000,
|
|
// Retrying a 401 or a missing API URL just delays the redirect and
|
|
// the not-connected panel.
|
|
retry: (count, error) =>
|
|
error instanceof NotConnected || error instanceof ApiError ? false : count < 1,
|
|
},
|
|
},
|
|
});
|