/**
 * The api-client throws the parsed JSON error body (`{ message, errors?, status }`)
 * on non-2xx, but TanStack types mutation errors as `Error`. Narrow safely
 * instead of casting — a network failure or thrown Error still has `.message`.
 */
export function apiErrorMessage(error: unknown, fallback: string): string {
  if (typeof error === 'object' && error !== null && 'message' in error) {
    const message = (error as { message?: unknown }).message;
    if (typeof message === 'string' && message.trim() !== '') return message;
  }
  return fallback;
}
