fix: JS should return an error if body is empty#1114
Merged
Conversation
Fix error handling for API responses with empty body. Previously, when the API returned an error status code (4xx/5xx) with an empty response body, the error was not properly caught, causing a crash when accessing undefined response data. Now correctly detects errors by checking if `error !== undefined` instead of relying on truthiness check.
🦋 Changeset detectedLatest commit: 6aee2b8 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 |
mishushakov
approved these changes
Feb 3, 2026
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.
Fix error handling for API responses with empty body. Previously, when the API returned an error status code (4xx/5xx) with an empty response body, the error was not properly caught, causing a crash when accessing undefined response data. Now correctly detects errors by checking if
error !== undefinedinstead of relying on truthiness check.Note
Low Risk
Small, localized change to client-side error detection plus new unit tests; main risk is slight behavior change for edge-case responses with falsy error values.
Overview
Fixes JS SDK API error detection for
openapi-fetchresponses where error bodies are empty (returned as''), by treatingresponse.error === undefinedas the only “no error” case instead of using a truthiness check.Adds a
vitestsuite forhandleApiErrorcovering empty-string error bodies across 4xx/5xx and special handling for401/429, plus success cases, and includes a patch changeset entry.Written by Cursor Bugbot for commit 6aee2b8. This will update automatically on new commits. Configure here.