Skip to content

feat: error handling + withResponse + includeClient option #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

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.

astahmer added 13 commits July 31, 2025 17:45
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.
Copy link

vercel bot commented Aug 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
typed-openapi-bzof ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 3, 2025 1:36pm

@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

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.
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

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

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