import { SiteAdminApiError } from "../client";

/**
 * What a failure says of itself: a sentence the client wrote for people, or
 * "" so the page uses its own copy.
 *
 * Only a `SiteAdminApiError` carries one: the clients throw it with a message
 * fit to show, or "" (`client.ts`). Any other error is not ours to show — a
 * rejected `fetch` is a `TypeError` in the browser's own English ("Failed to
 * fetch"), and it reached the toast as is, in every language (PR #1162
 * review).
 */
export const errorText = (err: unknown): string =>
  err instanceof SiteAdminApiError ? err.message : "";
