SonusLabSonusLab

Error Handling

Every SDK call returns a { result, error } tuple. No exceptions, no try/catch — just check error first.

The pattern

Destructure the named result and error. If error is not null, the result is null — and vice versa.

const { clip, error } = await sonus.clips.create({
  url: 'https://example.com/not-supported',
  start: 0,
  end: 10,
  name: 'test',
})

if (error) {
  console.error(error.status)
  console.error(error.message)
  console.error(error.body)
  return
}

console.log(clip.audioUrl)
error is always SonusLabError | null. Network failures, aborts, and HTTP errors all land in the same field.

Status codes

CodeMeaningDescription
400Bad RequestInvalid parameters — check your input
401UnauthorizedMissing or invalid API key
404Not FoundResource doesn't exist
409ConflictDuplicate name or resource conflict
429Too Many RequestsUsage limit reached for your plan
500Server ErrorSomething went wrong — retried automatically

Automatic retries

Failed requests are retried up to 2 times with exponential backoff on these status codes:

408429500502503504
Network errors and timeouts are also retried. The SDK uses Ky under the hood.

Aborting requests

Pass an AbortSignal to cancel any request. Aborted requests surface as an error with status: 0.

const controller = new AbortController()
setTimeout(() => controller.abort(), 5000)

const { clip, error } = await sonus.clips.create(
  { url: '...', start: 0, end: 10, name: 'test' },
  { signal: controller.signal },
)

if (error) {
  console.error(error.message)
  return
}

Usage limits

When you hit your plan's limit, error.status will be 429. Check usage in the dashboard or upgrade on the pricing page.