这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 12, 2025

Fix fetch client to intercept AbortError and other fetch exceptions

Summary

Fixed an issue where the fetch client was not intercepting exceptions thrown by the fetch call, such as AbortError (when a request is aborted) and network errors. These exceptions were propagating directly to the caller without going through error interceptors, unlike HTTP errors which were properly handled.

Changes

Main Fix (client.ts)

  • Wrapped the await _fetch(request) call in a try-catch block
  • When fetch throws an exception:
    • The error is passed through all registered error interceptors
    • If throwOnError is true, the transformed error is re-thrown
    • Otherwise, returns an error response object consistent with HTTP error handling

Tests (client.test.ts)

Added 4 comprehensive tests for exception handling:

  • Test that AbortError is intercepted and passed through error interceptors
  • Test that network errors are intercepted and passed through error interceptors
  • Test that with throwOnError: true, the transformed error is thrown
  • Test that without error interceptors, the original error is returned

Updates

  • Built packages
  • Updated 143 snapshot files with the new client code
  • Regenerated all 14 examples with updated client code
  • All tests passing (610 tests)

Verification Results

  • All 27 tests in client.test.ts pass ✅
  • All 610 tests in openapi-ts-tests pass ✅
  • All 14 examples regenerated ✅
  • TypeScript compilation succeeds ✅
  • Linting passes ✅
  • Build succeeds ✅

Behavior

Before: AbortError and network errors would throw directly, bypassing error interceptors
After: All fetch exceptions are caught, passed through error interceptors, and handled consistently

Original prompt

This section details on the original issue you should resolve

<issue_title>fetch client doesn't intercept AbortError</issue_title>
<issue_description>### Description

The fetch method is awaited directly, without try .. catch
When any HTTP error is returned, the method continues and eventually calls the error interceptor.
Contrary to this, when the passed signal is aborted, the exception get's thrown direcly from awaited fetch call - resuling in an unhandled exception.

Reproducible example or configuration

No response

OpenAPI specification (optional)

No response

System information (optional)

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@changeset-bot
Copy link

changeset-bot bot commented Nov 12, 2025

🦋 Changeset detected

Latest commit: 6a46317

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hey-api/openapi-ts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Nov 12, 2025

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

Project Deployment Preview Comments Updated (UTC)
hey-api-docs Ready Ready Preview Comment Nov 12, 2025 1:07pm

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix fetch client to intercept AbortError Fix fetch client to intercept AbortError and network exceptions Nov 12, 2025
Copilot AI requested a review from mrlubos November 12, 2025 12:03
Copilot finished work on behalf of mrlubos November 12, 2025 12:03
@mrlubos mrlubos marked this pull request as ready for review November 12, 2025 12:47
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 12, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 12, 2025
@dosubot dosubot bot added bug 🔥 Something isn't working client Client package related labels Nov 12, 2025
@mrlubos
Copy link
Member

mrlubos commented Nov 12, 2025

@copilot run pnpm test:update after building packages to update snapshots and make sure to update examples too

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Nov 12, 2025
Copy link
Contributor Author

Copilot AI commented Nov 12, 2025

@copilot run pnpm test:update after building packages to update snapshots and make sure to update examples too

Done! Built packages, updated 143 snapshot files and regenerated all 14 examples with the fetch exception handling changes. All 610 tests pass. (commit 6a46317)

@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 29.48%. Comparing base (8e0f205) to head (6a46317).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2970      +/-   ##
==========================================
+ Coverage   29.40%   29.48%   +0.08%     
==========================================
  Files         403      405       +2     
  Lines       35790    35841      +51     
  Branches     2065     2075      +10     
==========================================
+ Hits        10524    10568      +44     
- Misses      25239    25246       +7     
  Partials       27       27              
Flag Coverage Δ
unittests 29.48% <100.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 12, 2025

Open in StackBlitz

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/codegen-core@2970
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/nuxt@2970
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/openapi-ts@2970
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@2970

commit: 6a46317

@mrlubos mrlubos merged commit db28926 into main Nov 12, 2025
17 of 28 checks passed
@mrlubos mrlubos deleted the copilot/fix-fetch-client-aborterror branch November 12, 2025 13:29
@hey-api hey-api bot mentioned this pull request Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🔥 Something isn't working client Client package related lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fetch client doesn't intercept AbortError

2 participants