Errors
The contract exposes a stable error shape and code literals for machine-readable handling.
LegatoError
Section titled “LegatoError”interface LegatoError { code: LegatoErrorCode; message: string; details?: unknown;}Public error codes
Section titled “Public error codes”LegatoErrorCode is derived from LEGATO_ERROR_CODES:
const LEGATO_ERROR_CODES = [ 'player_not_setup', 'invalid_index', 'empty_queue', 'no_active_track', 'invalid_url', 'load_failed', 'playback_failed', 'seek_failed', 'unsupported_operation', 'platform_error',] as const;Handling guidance
Section titled “Handling guidance”- Branch logic on
error.codebecause it is the stable machine-readable contract. - Treat
error.messageas human-readable runtime text, not as a stable parser target. - Use
detailsonly as optional, transport-specific context.
Minimal example
Section titled “Minimal example”import type { LegatoError } from '@ddgutierrezc/legato-contract';
function classify(error: LegatoError): 'retry' | 'fatal' { if (error.code === 'load_failed' || error.code === 'playback_failed') { return 'retry'; }
return 'fatal';}