Skip to content

fix(sonarr): handle empty response bodies - #10

Merged
naveedious merged 1 commit into
mainfrom
fix/sonarr-empty-response-body
Aug 29, 2026
Merged

naveedious merged 1 commit into
mainfrom
fix/sonarr-empty-response-body

Conversation

@naveedious

Copy link
Copy Markdown
Owner

Bug

Auto-remediation log showed: api: failed: Unexpected end of JSON input

Sonarr replies to DELETE /episodefile/{id} with HTTP 200 + empty body. sonarrReq() unconditionally called res.json(), which threw after the delete had already succeeded — aborting the try-block before searchEpisode() ran. Result: corrupt file deleted, but no replacement download queued (only self-healed on the next poll/webhook).

Fix

sonarrReq() now reads the body as text first; empty → null. Non-empty still parses as JSON. One-line behaviour change, no API contract change.

Test plan

  • node --check src/sonarr.js
  • node --test tests/*.test.js — 4/4 pass
  • Post-deploy: next runtime_too_short remediation shows delete + re-search both ok

… no JSON)

Sonarr replies to DELETE /episodefile/{id} with HTTP 200 and an empty body.
sonarrReq() unconditionally called res.json(), throwing 'Unexpected end of
JSON input' after the delete succeeded — which aborted the try-block before
searchEpisode() ran, so no replacement download was queued.

Now: empty body -> null. Delete + re-search complete in one pass.
@naveedious
naveedious merged commit b949a78 into main Aug 29, 2026
1 check passed
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