Repository navigation
Align responseStyle types and stabilize SDK error contracts #94
Description
Part of v1.0.0 getsentry/sentry-api-schema#93. This is the response/error foundation for CLI, MCP, the frontend, and external consumers. Frontend inference and runtime adoption are separate follow-ups: #102 and #103.
Problem
Generated operations accept responseStyle: "data" and return only the parsed body at runtime, but their TypeScript return type still exposes the fields envelope, including response. Code that reads headers therefore typechecks and then fails. This predates the object-client DX change and affects standalone and bound operations.
const result = await listOrganizations({
baseUrl: "https://example.test",
responseStyle: "data",
fetch: async () => Response.json([]),
});
// Currently typechecks, but result is an array and result.response is undefined.
result.response.headers.get("Link");Contract to settle here
Use fields as the primary public result contract:
// Success
{ data, request, response }
// HTTP failure with throwOnError: false
{ error, request, response }
// A failure without an HTTP response
{ error, request, response: undefined }These describe the relevant fields; exact discriminant/property optionality must agree between runtime and types. Received headers are response.headers; outgoing headers are request.headers. throwOnError: true rejects on failure without changing the successful result shape.
- Resolve the currently exposed
responseStyle: "data"configuration explicitly: support it with accurate types or constrain/reject it with documented 0.x migration guidance. Do not silently change runtime output to make a type test pass. - Make initial config, per-call overrides, and supported
setConfigupdates agree with runtime/types across bound, standalone, and injected-client operations. - Type absent HTTP responses honestly. Preserve status/body/headers for actual responses, including undocumented error statuses.
- Define consistent default HTTP-error behavior using the existing
SentryApiError: returning an error and throwing it should describe the same failure. Preserve original error text and parsed body during the existing body read, with request/response context and causes where applicable. Consumers should not need a WeakMap, response clone, or JSON reserialization to reconstruct error metadata. - Respect an intentional consumer error mapping. A returned/custom-thrown error must not be silently replaced by later normalization or pagination. Document interceptor ordering and verify exact error identity where propagation is promised.
- Keep custom-fetch/application exceptions, cancellation, decoding/validation failures, and HTTP failures distinct. A catch-all must not label every exception as a pre-response network failure.
- Reconcile existing pagination and typed-error helpers with this contract. Explicit status-narrowing helpers may retain a documented opt-in result contract; they must not be inserted transparently into consumers that chose their own errors. Document any deliberate changes rather than silently redesigning those helpers.
- Verify runtime and compile-time behavior for success, HTTP errors, absent responses, configuration precedence, custom errors, interceptors, and representative pagination/error helpers. Error-body types remain limited by the schema; a documented status is not runtime payload validation.
What is outside #94
- Migrating
RequestError,apiOptions, frontend components, or the frontend transport. - Generating the frontend operation map or implementing a TanStack plugin.
- Shipping a frontend-specific compatibility module or deciding a new
errorFactory/ constructor-injection API. - Implementing cancellation composition (Preserve AbortSignal across SDK fetch adapters #95), retries (Ship opt-in transport retries and per-request controls for v1 #92), or auth/browser/routing behavior (feat: SDK auth/client config factories (bearerToken, browserSession, createSentryClient) #78/feat: opt-in direct region routing (resolveRegionUrl) #79).
The frontend must be able to keep its real RequestError; #94 provides the stable context and propagation guarantees for a later shared integration. It does not make the SDK responsible for login/SSO/sudo, UI messages, CLI exit codes, or MCP tool responses.
Keep implementation PRs focused. If a remaining error/helper change needs a separate PR, retain a linked unchecked requirement here or in #93; fixing only the type mismatch must not imply the broader contract has shipped.
Following work
- #102: generate contracts consumed by existing
apiOptions, retainingapiFetch → Clientand therefore existing errors/auth/cache. This has no technical dependency on replacing the transport and can progress in parallel. - #103: adopt SDK runtime mechanics in shared infrastructure, supply reusable adaptation from the SDK where needed, and prove actual frontend workflows. This consumes Align responseStyle types and stabilize SDK error contracts #94 and the relevant cancellation/auth/routing contracts.
Investigate generator configuration/post-processing or upstream Hey API before adding another abstraction. The inspected build uses Hey API 0.91.1; recheck the chosen generator version. Typed-error wrappers getsentry/sentry-api-schema#84 currently force fields for their own calls and do not fix direct operations.
Activity
feat: add configured clients with bound API methods (#98)
feat: bind pagination helpers to configured clients (#100)
[-]Align responseStyle return types with runtime results[/-][+]Align responseStyle types and stabilize SDK error contracts[/+]fix: stabilize SDK response and error contracts (#104)