import { SourceError } from "@/lib/research/sources"; // Every research route answers JSON, never cached, and an error in words: // a SourceError carries its own status (400 a bad request, 404 nothing there, // 502 a source that cannot be read); anything else is a 500. export function ok(body: unknown): Response { return Response.json(body, { headers: { "cache-control": "no-store" } }); } export function fail(e: unknown): Response { const status = e instanceof SourceError ? e.status : ((e as { status?: number })?.status ?? 500); return Response.json({ error: (e as Error)?.message ?? String(e) }, { status, headers: { "cache-control": "no-store" } }); }