Skip to content

Fix: handle non-JSON Invidious API responses gracefully#8756

Closed
Houmgaor wants to merge 1 commit intoFreeTubeApp:developmentfrom
Houmgaor:fix/invidious-non-json-response
Closed

Fix: handle non-JSON Invidious API responses gracefully#8756
Houmgaor wants to merge 1 commit intoFreeTubeApp:developmentfrom
Houmgaor:fix/invidious-non-json-response

Conversation

@Houmgaor
Copy link

@Houmgaor Houmgaor commented Mar 6, 2026

Summary

  • When an Invidious instance returns non-JSON responses (e.g. plain text "API disabled"), the app currently crashes with SyntaxError: Unexpected token 'A', "API disabled" is not valid JSON
  • This change reads the response as text first, checks response.ok, and wraps JSON.parse in a try/catch, so the actual server message is surfaced as the error instead of a cryptic JSON parse failure
  • This is the single most commonly reported error in the app, affecting users whose Invidious instances have disabled their APIs

relates to #7883, #8527, #5720, #5506

Test plan

  • Configure an Invidious instance that has its API disabled and verify the error message now shows the actual server response (e.g. "API disabled") instead of a JSON SyntaxError
  • Verify normal Invidious API usage still works correctly with a working instance
  • Verify that Invidious JSON error responses (e.g. {"error": "..."}) are still handled as before

@FreeTubeBot FreeTubeBot enabled auto-merge (squash) March 6, 2026 09:42
@github-actions github-actions bot added the PR: waiting for review For PRs that are complete, tested, and ready for review label Mar 6, 2026
When an Invidious instance returns non-JSON responses (e.g. "API disabled"
plain text), the app previously crashed with a cryptic SyntaxError from
JSON.parse. Now the response is read as text first, HTTP status is checked,
and JSON parsing is wrapped in a try/catch, so the actual server message
(e.g. "API disabled") is shown as the error instead.

Fixes FreeTubeApp#7194, fixes FreeTubeApp#7160, relates to FreeTubeApp#7883, FreeTubeApp#8527, FreeTubeApp#5720, FreeTubeApp#5506
auto-merge was automatically disabled March 6, 2026 09:46

Head branch was pushed to by a user without write access

@FreeTubeBot FreeTubeBot enabled auto-merge (squash) March 6, 2026 09:46
auto-merge was automatically disabled March 6, 2026 09:47

Pull request was closed

@github-actions github-actions bot removed the PR: waiting for review For PRs that are complete, tested, and ready for review label Mar 6, 2026
@FreeTubeApp FreeTubeApp locked as spam and limited conversation to collaborators Mar 6, 2026
@absidue
Copy link
Member

absidue commented Mar 6, 2026

Please refrain from using AI/LLMs to create issues, pull requests, comments, or any other content submitted to the FreeTube project.

https://docs.freetubeapp.io/community/rules/

@efb4f5ff-1298-471a-8973-3d47447115dc efb4f5ff-1298-471a-8973-3d47447115dc added the AI-PR PR that has been determined to be completely or majority untested and AI generated label Mar 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

AI-PR PR that has been determined to be completely or majority untested and AI generated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants