Skip to content

fix: resolve double response body read in handleSync #2284

Open
just-tanvi wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
just-tanvi:fix/issue-1-goal-sync-error
Open

fix: resolve double response body read in handleSync #2284
just-tanvi wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
just-tanvi:fix/issue-1-goal-sync-error

Conversation

@just-tanvi

Copy link
Copy Markdown

Description

This PR fixes a bug in the handleSync function where the fetch response body was being consumed twice when the API returned an HTTP 429 Too Many Requests status code.

Previously, the first .json() call inside the initial try/catch consumed the response stream, causing a subsequent .json() call in the 429 status check block to throw a TypeError: body stream already read. This swallowed the intended rate limit error message and resulted in a generic "Network error. Failed to sync goals." being shown to the user.

Changes Made

  • Refactored handleSync in src/components/GoalTracker.tsx to read the response body exactly once into an errData variable.
  • Used the stored errData to properly branch on res.status (429, 401, 502, etc.) without re-reading the stream.
  • Removed dead code (the unused msg variable).
  • Ensured the fallback error message matches the existing test/GoalTracker.test.ts expectations ("Sync failed. Please try again.").

Testing

  • Verified that all unit tests in test/GoalTracker.test.ts pass successfully.
  • Verified that TypeScript compilation (tsc --noEmit) passes with zero errors.

closes #2283

@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

@just-tanvi is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:feature GSSoC type bonus: new feature type:design GSSoC type bonus: UI/design (+10 pts) type:performance GSSoC type bonus: performance (+15 pts) and removed gssoc26 GSSoC 2026 contribution labels Jun 10, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

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

Labels

type:bug GSSoC type bonus: bug fix type:design GSSoC type bonus: UI/design (+10 pts) type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] handleSync reads response body twice on HTTP 429, silently swallowing the rate-limit error message

1 participant