Skip to content

Error handling

import {
VyonicaClient,
AuthenticationError,
QuotaExceededError,
JobFailedError,
JobTimeoutError,
VyonicaError,
} from 'vyonica';
const client = new VyonicaClient({ apiKey: 'nvsk_...' });
try {
const audio = await client.clone(refWav, { text: 'Hello' });
fs.writeFileSync('output.wav', audio);
} catch (e) {
if (e instanceof AuthenticationError) {
console.error('Bad API key — check your credentials');
} else if (e instanceof QuotaExceededError) {
console.error('Rate limit hit — slow down or upgrade your plan');
} else if (e instanceof JobFailedError) {
console.error(`Job ${e.jobId} failed: ${e.errorMessage}`);
} else if (e instanceof JobTimeoutError) {
console.error(`Job ${e.jobId} timed out`);
} else if (e instanceof VyonicaError) {
console.error(`API error ${e.statusCode}: ${e.message}`);
} else {
throw e; // re-throw unexpected errors
}
}

When each error is thrown

ErrorCause
AuthenticationErrorHTTP 401 — missing, malformed, inactive, or expired API key.
QuotaExceededErrorHTTP 429 — daily request cap or lifetime minute cap exceeded. See Usage & quota.
JobFailedErrorJob reached status failed. e.jobId and e.errorMessage are populated.
JobTimeoutErrorclient.clone() exceeded pollOptions.timeoutMs without the job completing.
VyonicaErrorAny other non-2xx response. Inspect e.statusCode and e.message.

All four specialized errors extend VyonicaError, so a single catch (e: VyonicaError) works for callers that only need to log.