/** * The one place a thrown value is turned into a developer-facing message. * * Five copies of this logic drifted apart across the composables and stores * (some checked a bare `{ message }` object, some did not); this export is the * union of what they all accepted, so every caller now reads the same message * from the same value. */ export function readErrorMessage(value: unknown, fallback = 'Request failed.'): string { if (value instanceof Error && value.message) { return value.message } if (typeof value === 'string' && value.trim()) { return value } if ( typeof value === 'object' && value !== null && 'message' in value && typeof (value as { message?: unknown }).message === 'string' && (value as { message: string }).message.trim() ) { return (value as { message: string }).message } return fallback }