Skip to content

fix: check res.ok before parsing JSON in via-rest.ts - #507

Open
saurabhhhcodes wants to merge 1 commit into
UTSAVS26:mainfrom
saurabhhhcodes:fix/json-ok-check
Open

fix: check res.ok before parsing JSON in via-rest.ts#507
saurabhhhcodes wants to merge 1 commit into
UTSAVS26:mainfrom
saurabhhhcodes:fix/json-ok-check

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Jul 28, 2026

Copy link
Copy Markdown

Move the if (!res.ok) check before res.json() in via-rest.ts to ensure the response status is validated before attempting to parse the body as JSON.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for failed requests.
    • Requests now report the HTTP status and URL immediately when the server returns an unsuccessful response, including responses with unexpected content.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Thank you for opening this pull request! We're excited to review your contribution. Please give us a moment, and we'll get back to you shortly!

Feel free to join our community on Discord to discuss more!

@github-actions
github-actions Bot requested review from UTSAVS26 and pavitraag July 28, 2026 07:42
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 94890640-5090-46c6-b804-f24a104f2f50

📥 Commits

Reviewing files that changed from the base of the PR and between 9f6eda4 and fbf44d2.

📒 Files selected for processing (1)
  • stargazers/src/fetch/via-rest.ts

📝 Walkthrough

Walkthrough

The REST fetch helper now checks res.ok before parsing JSON and throws immediately for non-OK responses with the status and URL.

Changes

REST response validation

Layer / File(s) Summary
Validate responses before JSON parsing
stargazers/src/fetch/via-rest.ts
Moves the non-OK response check ahead of res.json(), preserving the status and URL in the thrown error.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: validating res.ok before parsing JSON in via-rest.ts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

1 participant