Skip to content

Conversation

astahmer
Copy link
Owner

@astahmer astahmer commented Aug 1, 2025

Improves type-safe API error handling and response access

Refactors API client response typing to unify success and error data under a consistent interface.
Replaces separate error property with direct data access and ensures the Response object retains its methods.
Updates documentation with clearer examples for type-safe error handling and data access patterns.
Facilitates more ergonomic and predictable client usage, especially for error cases.

Copy link

vercel bot commented Aug 1, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
typed-openapi-bzof Ready Ready Preview Comment Aug 24, 2025 2:42pm

@astahmer astahmer changed the title Feat/error-handling feat: error handling + withResponse + includeClient option Aug 1, 2025
@astahmer astahmer requested a review from Copilot August 1, 2025 12:12
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces improved type-safe error handling and response access capabilities to the typed OpenAPI client. It adds a withResponse option that allows developers to access both success and error responses through a unified interface while maintaining backward compatibility.

  • Adds withResponse parameter to enable type-safe error handling with Response object access
  • Unifies response data access pattern with consistent data property for both success and error cases
  • Introduces responses schema definitions for all endpoints to support proper error typing

Reviewed Changes

Copilot reviewed 36 out of 36 changed files in this pull request and generated 5 comments.

File Description
test-new-api.ts Test file demonstrating the new withResponse API with type inference validation
packages/typed-openapi/tests/snapshots/*.ts Updated all client variations (zod, yup, valibot, typebox, io-ts, client, arktype) with new error handling types and withResponse method overloads

Copy link

pkg-pr-new bot commented Aug 3, 2025

Open in StackBlitz

npm i https://pkg.pr.new/astahmer/typed-openapi@92

commit: 9952737

Copy link

pkg-pr-new bot commented Aug 3, 2025

Open in StackBlitz

npm i https://pkg.pr.new/astahmer/typed-openapi@92

commit: 6441c58

Adds CLI options for client inclusion and success codes

Introduces flags to control API client generation and customize success status codes via the command line, enhancing flexibility for different use cases.
Improves type-safe API error handling and response access

Refactors API client response typing to unify success and error data under a consistent interface.
Replaces separate error property with direct data access and ensures the Response object retains its methods.
Updates documentation with clearer examples for type-safe error handling and data access patterns.
Facilitates more ergonomic and predictable client usage, especially for error cases.
Adds type-safe error handling to TanStack Query generator

Introduces discriminated unions and configurable success status codes for more robust error handling in generated TanStack Query clients.

Supports advanced mutation options with `withResponse` and `selectFn` to enable granular control over success and error transformations in API responses.

Improves documentation to highlight new error handling features and integration patterns.
@astahmer astahmer merged commit 8f1eaa5 into main Aug 24, 2025
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