Skip to content

feat(sdk): align request errors, retry delays and client cloning - #8

Merged
moonyue-w merged 2 commits into
mainfrom
codex/align-ts-api-errors
Sep 24, 2026
Merged

moonyue-w merged 2 commits into
mainfrom
codex/align-ts-api-errors

Conversation

@moonyue-w

Copy link
Copy Markdown
Collaborator

Summary

Align TypeScript request-error classification, retry-delay boundaries, and client cloning with the pinned Anthropic sdk-v0.127.0 baseline.

  • Make connection failures, timeouts, and user cancellation inherit from APIError, preserving existing constructors and causes. HTTP status/header metadata remains absent on non-HTTP errors.
  • Honor only positive retry delays within the single-timer limit; invalid, zero, negative, and oversized values use exponential backoff. Align millisecond-header precedence without changing retry eligibility.
  • Add withOptions() to derive a client of the same concrete type, preserving unspecified settings, credentials, custom fetch, middleware, and the resolved base URL. Supplied client-level headers, query defaults, and middleware replace the corresponding option.
  • Update resumable-stream classification, conformance tests, public types, README, changelog, and generated API documentation.

Why

Allow a single APIError catch to cover request failures, prevent oversized delays from becoming immediate retries, and make configuration reuse consistent across clients.

Verification

  • npm run build: CommonJS and ESM build passed.
  • npm run typecheck: passed, including derived-client and error-subclass types.
  • npm test: 3,375 passed.
  • npm run docs:check: passed; 26 README TypeScript snippets compiled.
  • Standalone examples were not rerun; example files are unchanged and README examples were typechecked.
  • Live integration runs are not required for these changes: existing live suites use maxRetries: 0; controlled transport tests exercise retry timing, error classification, and derived-client configuration.

Impact

  • Public behavior/API changes recorded under Unreleased.
  • CommonJS, ESM, and subpath exports remain covered by build/type tests.
  • Generated API documentation and contract tests updated. Endpoint and wire-field fixtures are unchanged.
  • Cross-SDK behavior considered; QCA retry safety rules retained.
  • Migration notes included; no credentials, environment files, logs, or test output committed.

Breaking change: instanceof APIError now includes connection, timeout, and cancellation errors. Guard optional status and headers, and handle APIUserAbortError first when cancellation needs separate treatment. Existing HTTP-specific subclasses retain their typed metadata.

@moonyue-w
moonyue-w merged commit b5836c6 into main Sep 24, 2026
5 checks passed
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.

1 participant