Skip to content

fix(douyin): handle empty response body in browserFetch#1408

Open
kagura-agent wants to merge 1 commit intojackwener:mainfrom
kagura-agent:fix/browser-fetch-empty-response
Open

fix(douyin): handle empty response body in browserFetch#1408
kagura-agent wants to merge 1 commit intojackwener:mainfrom
kagura-agent:fix/browser-fetch-empty-response

Conversation

@kagura-agent
Copy link
Copy Markdown
Contributor

Problem

opencli douyin hashtag search --keyword King crashes with SyntaxError: Unexpected end of JSON input when the Douyin API returns HTTP 200 with an empty body (content-length: 0).

The root cause is that browserFetch calls res.json() directly without checking if the response body is empty.

Fix

  • Read response as text first (res.text()), return null for empty bodies
  • At the caller level, throw a descriptive CommandExecutionError('Empty response from Douyin API') instead of an opaque JSON parse error

This benefits all 20 douyin commands that use browserFetch.

Testing

  • Added 2 test cases for null/undefined responses
  • All 100 existing douyin tests pass
  • npx vitest run clis/douyin/

Closes #1405

browserFetch calls res.json() directly, which throws SyntaxError when
the API returns an empty body (content-length: 0). This happens when
the Douyin hashtag search endpoint returns HTTP 200 with no content.

Fix: read response as text first, return null for empty bodies, then
throw a descriptive CommandExecutionError at the caller level.

Fixes jackwener#1405
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.

douyin hashtag search 返回空响应导致 JSON 解析失败 (SyntaxError: Unexpected end of JSON input)

1 participant