fix(openapi-fetch): use text() when no content-length is provided to avoid errors parsing empty response (200 with no content)#2508
Merged
drwpow merged 1 commit intoopenapi-ts:mainfrom Feb 8, 2026
Conversation
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: a38257a The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
Contributor
Author
|
Related issue: #1977 |
1 task
drwpow
approved these changes
Feb 8, 2026
Contributor
drwpow
left a comment
There was a problem hiding this comment.
Makes sense. Good tests, thank you!
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Fixes an issue where responses with HTTP 200 status and no
Content-Lengthheader would fail when parsing JSON, even when the response body is empty.Problem: When a server returns a successful response (200 OK) without a
Content-Lengthheader and an empty body, callingresponse.json()directly throws an error because there's no content to parse. This is a valid HTTP scenario but was causing runtime errors.Solution: Added a check for missing
Content-Lengthheaders whenparseAs: "json". The fix:response.text()undefinedif the response is emptyHow to Review
index.jsaround line 245 that handles the case whenparseAs === "json" && !contentLength"json with empty response"inresponse.test.tsverifies the fix works correctlyparseAsis set to"json"(default)Content-Lengthheader is absent (not just"0")Key review points:
{ data: undefined }instead of throwing an errorContent-Length: "<any>"are still handled by the existing logicparseAsoptionsChecklist
docs/updated (if necessary) - No docs changes needed, internal bug fixpnpm run update:examplesrun (only applicable for openapi-typescript) - N/A, this is openapi-fetch