fix(client-fetch): type response as Response | undefined in error interceptors#3750
fix(client-fetch): type response as Response | undefined in error interceptors#3750inas-sirhan wants to merge 3 commits intohey-api:mainfrom
Conversation
…erceptors and error results When fetch() throws (network failure, AbortError, etc.), the error interceptor is called with undefined for the response parameter, and the error result also has an undefined response. Previously, both the ErrInterceptor type and RequestResult type incorrectly typed response as always-defined Response, requiring unsafe `as any` casts. This change makes the types honest: - ErrInterceptor: response parameter is now Res | undefined - RequestResult: response in the error branch is now Response | undefined - Removes `undefined as any` casts in the client implementation Closes hey-api#3519
|
|
🦋 Changeset detectedLatest commit: 9d97fb3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
@inas-sirhan is attempting to deploy a commit to the Hey API Team on Vercel. A member of the Team first needs to authorize it. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3750 +/- ##
==========================================
+ Coverage 38.38% 40.04% +1.65%
==========================================
Files 520 520
Lines 19228 19243 +15
Branches 5689 5720 +31
==========================================
+ Hits 7380 7705 +325
+ Misses 9587 9342 -245
+ Partials 2261 2196 -65
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
TL;DR — When a Key changes
Summary | 510 files | 3 commits | base:
The core change is 4 single-line edits across 3 source files in the
|
There was a problem hiding this comment.
Reviewed — no issues found.
The fix correctly types response as Response | undefined in error interceptors and error results, matching the runtime behavior when fetch() throws (network failure, AbortError, etc.). The undefined as any casts are properly removed since the types now accommodate undefined. The ThrowOnError extends true branch is correctly left untouched — when throwOnError is enabled, fetch exceptions are re-thrown and the promise never resolves, so response: Response remains accurate there.
Note: client-angular has a similar pattern where result.response starts as null and uses as any in its error path — that could be addressed in a follow-up.
Task list (4/4 completed)
- Read and analyze the PR diff
- Investigate source changes to client-fetch types and implementation
- Verify snapshot changes are consistent with source changes
- Self-critique drafted comments and submit review
@hey-api/codegen-core
@hey-api/json-schema-ref-parser
@hey-api/nuxt
@hey-api/openapi-ts
@hey-api/shared
@hey-api/spec-types
@hey-api/types
@hey-api/vite-plugin
commit: |

Fixes #3519
The
ErrInterceptortype andRequestResulttype incorrectly typedresponseas always-definedResponse. Whenfetch()throws (network failure,AbortError, etc.), the error interceptor receivesundefinedforresponse, and the error result also returnsundefinedforresponse.Changes:
ErrInterceptor:responseparameter is nowRes | undefinedRequestResult(non-throw error branch):responseis nowResponse | undefinedundefined as anycasts in the client implementation