Skip to content

fix: JS should return an error if body is empty#1114

Merged
dobrac merged 2 commits intomainfrom
fix/js-should-return-error-empty-body
Feb 3, 2026
Merged

fix: JS should return an error if body is empty#1114
dobrac merged 2 commits intomainfrom
fix/js-should-return-error-empty-body

Conversation

@dobrac
Copy link
Contributor

@dobrac dobrac commented Feb 3, 2026

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.


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-fetch responses where error bodies are empty (returned as ''), by treating response.error === undefined as the only “no error” case instead of using a truthiness check.

Adds a vitest suite for handleApiError covering empty-string error bodies across 4xx/5xx and special handling for 401/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.

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.
@dobrac dobrac added the bug Something isn't working label Feb 3, 2026
@changeset-bot
Copy link

changeset-bot bot commented Feb 3, 2026

🦋 Changeset detected

Latest commit: 6aee2b8

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

This PR includes changesets to release 1 package
Name Type
e2b 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

@dobrac dobrac enabled auto-merge (squash) February 3, 2026 16:47
@dobrac dobrac merged commit 1780a0c into main Feb 3, 2026
16 of 17 checks passed
@dobrac dobrac deleted the fix/js-should-return-error-empty-body branch February 3, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants