Skip to content

feat(errors): introduce AssemblyAIError with HTTP status and retryAfter (#80) - #203

Open
pylrn wants to merge 1 commit into
AssemblyAI:mainfrom
pylrn:feat/assemblyai-error-status-retry-after
Open

pylrn wants to merge 1 commit into
AssemblyAI:mainfrom
pylrn:feat/assemblyai-error-status-retry-after

Conversation

@pylrn

@pylrn pylrn commented Oct 31, 2026

Copy link
Copy Markdown

Summary

Resolves #80 by introducing AssemblyAIError as the base error class for HTTP and API errors across the Node SDK, exposing the HTTP status code and any numeric retryAfter delay from Retry-After response headers.

Why

Previously, when HTTP requests failed in BaseService.fetch (e.g., client.transcripts.submit, client.transcripts.get, client.files.upload), the SDK threw a generic Error with only a string message. Callers had no way to distinguish client errors (e.g. 400 Bad Request) from transient / retriable server errors (e.g. 429 Too Many Requests, 500/503), nor could they inspect the Retry-After delay header.

Changes

  • AssemblyAIError class (src/utils/errors/assemblyai.ts):
    • Extends Error with public readonly status?: number and public readonly retryAfter?: number.
    • Maintains full backwards compatibility with Error and existing message strings.
  • BaseService.fetch (src/services/base.ts):
    • Throws AssemblyAIError instead of generic Error on 4xx/5xx responses.
    • Extracts message from json.error, raw text, or HTTP status fallback (exact same precedence and message strings as before).
    • Parses Retry-After header as integer seconds if present and formatted as digits.
  • Error hierarchy unification (src/utils/errors/):
    • SyncTranscriptError, DictationError, LlmGatewayError, and TextToSpeechError now extend AssemblyAIError, allowing users to catch AssemblyAIError for any AssemblyAI API failure across services (matching the architecture in assemblyai-python-sdk).
  • Exports:
    • Exported from package root via ./services and root entry point.
  • Unit tests:
    • Added tests/unit/assemblyai-error.test.ts covering JSON error bodies, plain text responses, empty bodies, and Retry-After extraction.
    • Updated tests/unit/exports.test.ts to verify root exports and inheritance.

Verification

  • tsc --noEmit: 0 errors.
  • rollup -c: successfully built all 12 distribution bundles (ESM, CJS, Deno, Bun, workerd, browser, UMD).
  • eslint: clean on all modified and new files.
  • prettier: formatted cleanly.
  • Jest unit tests: all passing.

…er (AssemblyAI#80)

- Add AssemblyAIError extending Error with status?: number and retryAfter?: number
- Update BaseService.fetch to throw AssemblyAIError instead of generic Error, preserving exact error messages from JSON error bodies, plain text, or HTTP status fallback while attaching HTTP status code and Retry-After header value when present
- Make SyncTranscriptError, DictationError, LlmGatewayError, and TextToSpeechError inherit from AssemblyAIError to unify error handling across all SDK services
- Export AssemblyAIError from package root
- Add unit tests covering JSON error, plain text error, empty body, and Retry-After header extraction, along with inheritance checks

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add more robust error messaging

1 participant