/** * Turning a failed request into a sentence somebody can act on. * * The three that matter are genuinely different problems and send you to different places: nothing is * configured yet, fofos cannot be reached, or fofos refused the token. A panel that says "something * went wrong" for all three is the reason people restart servers that were fine. */ export type ApiFailure = { error?: string; /** No connection stored. A setup step, not a fault. */ unconfigured?: boolean; /** fofos never answered — down, wrong URL, no route to it. */ unreachable?: boolean; }; /** What the client throws carries the parsed body on `.body` when there was one. */ export const failureOf = (error: unknown): ApiFailure => { const body = (error as { body?: unknown })?.body; if (body && typeof body === 'object') return body as ApiFailure; return { error: error instanceof Error ? error.message : String(error) }; }; export const readableError = (error: unknown): string => { const failure = failureOf(error); if (failure.unconfigured) return 'No fofos connection is set up yet.'; if (failure.unreachable) return failure.error ?? 'fofos did not answer.'; return failure.error ?? 'That did not work, and the server did not say why.'; };