Repository navigation
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #80 by introducing
AssemblyAIErroras the base error class for HTTP and API errors across the Node SDK, exposing the HTTPstatuscode and any numericretryAfterdelay fromRetry-Afterresponse 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 genericErrorwith 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 theRetry-Afterdelay header.Changes
AssemblyAIErrorclass (src/utils/errors/assemblyai.ts):Errorwithpublic readonly status?: numberandpublic readonly retryAfter?: number.Errorand existing message strings.BaseService.fetch(src/services/base.ts):AssemblyAIErrorinstead of genericErroron 4xx/5xx responses.json.error, raw text, or HTTP status fallback (exact same precedence and message strings as before).Retry-Afterheader as integer seconds if present and formatted as digits.src/utils/errors/):SyncTranscriptError,DictationError,LlmGatewayError, andTextToSpeechErrornow extendAssemblyAIError, allowing users to catchAssemblyAIErrorfor any AssemblyAI API failure across services (matching the architecture inassemblyai-python-sdk)../servicesand root entry point.tests/unit/assemblyai-error.test.tscovering JSON error bodies, plain text responses, empty bodies, andRetry-Afterextraction.tests/unit/exports.test.tsto 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.