Skip to content

fix: surface API errors that have an empty response body - #209

Open
SAY-5 wants to merge 1 commit into
tolgee:mainfrom
SAY-5:fix-empty-error-body
Open

SAY-5 wants to merge 1 commit into
tolgee:mainfrom
SAY-5:fix-empty-error-body

Conversation

@SAY-5

@SAY-5 SAY-5 commented Aug 25, 2026 •

Copy link
Copy Markdown

Fixes #208. When an error response has an empty body (e.g. a 429 from a proxy), openapi-fetch leaves error empty, so handleLoadableError let it through and tolgee pull crashed later with Cannot read properties of undefined (reading 'arrayBuffer'). Now the response status is checked as well, so the user gets the proper error message (rate limited, status code) instead of the crash.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for unsuccessful responses, including responses with empty bodies.
    • Correctly handles “not modified” responses without treating them as errors.
    • Improved handling of rate-limited responses.
  • Tests

    • Added coverage for successful responses, parsed errors, empty-body errors, and rate-limited responses.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 43d478c6-7760-4514-b14b-b91c656d0285

📥 Commits

Reviewing files that changed from the base of the PR and between 7172800 and 6345770.

📒 Files selected for processing (3)
  • src/client/TolgeeClient.ts
  • src/commands/pull.ts
  • test/unit/handleLoadableError.test.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

The pull command now distinguishes not-modified responses before error handling. Failed responses with undefined or empty error bodies now throw. Unit tests cover successful, parsed-error, rate-limit, undefined-body, and empty-body responses.

Changes

Error handling and pull response flow

Layer / File(s) Summary
Loadable error contract and validation
src/client/TolgeeClient.ts, test/unit/handleLoadableError.test.ts
handleLoadableError now rejects unsuccessful responses even when the error body is undefined or empty. Tests cover success, parsed errors, rate limits, and empty bodies.
Pull response handling
src/commands/pull.ts
fetchZipBlob computes notModified before error handling and skips handleLoadableError for HTTP 412 and 304 responses. The returned object shape is unchanged.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 63457

This PR makes empty-body API error responses surface the proper status-based error instead of causing a later crash. No actionable merge-blocking risk remains after normal checks and review.

Poem

A rabbit checks the empty stream,
And keeps the pull response clean.
If errors hide with bodies bare,
The handler finds them waiting there.
Not-modified paths hop ahead,
While tests watch every branch instead.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: surfacing API errors when the response body is empty.
Linked Issues check ✅ Passed The changes address issue [#208] by handling unsuccessful responses without error payloads and preventing the undefined response from causing Cannot read properties of undefined (reading 'arrayBuffer'…
Out of Scope Changes check ✅ Passed All changes are within scope. They update API error handling and add focused unit tests for the behavior required by [#208].
Full details: Linked Issues check

Explanation

The changes address issue [#208] by handling unsuccessful responses without error payloads and preventing the undefined response from causing Cannot read properties of undefined (reading 'arrayBuffer'). The added tests cover empty-body error responses.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot read properties of undefined (reading 'arrayBuffer')

1 participant