Skip to content

fix: check status code before decoding getJSON responses (!strims) - #66

Merged
jbpratt merged 1 commit into
MemeLabs:masterfrom
nom-d-plume:feature/strims-command
Sep 27, 2026
Merged

jbpratt merged 1 commit into
MemeLabs:masterfrom
nom-d-plume:feature/strims-command

Conversation

@nom-d-plume

@nom-d-plume nom-d-plume commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

!strims/!stream has been returning error getting api data in chat.

Root cause

This was originally an unclosed resp.Body leak in getStreamList,
which #65 (Modernize) already fixed as part of the getJSON refactor.
Rebased onto that; the remaining gap is that getJSON (backing
getStreamList/!strims and getProfileInfo) still decodes the
response body regardless of resp.StatusCode. A non-200 response
(5xx, rate limiting, an edge/WAF error page, etc.) gets fed straight
into json.Decoder, producing either a confusing decode error or a
silently empty result if the error body happens to parse as valid
JSON of a different shape.

Fix

Check resp.StatusCode in getJSON and fail fast with a descriptive
error before decoding.

Verification

  • go build ./..., go vet ./..., go test ./... all pass.
  • Manual repro: called printTopStreams with logOnly=true against the
    live https://strims.gg/api endpoint on top of current master;
    confirmed it returns the top 3 streams correctly, e.g.:
    13 strims.gg/angelthump/nomdeplume [nsfw]
    6 strims.gg/angelthump/gwsd7259
    6 strims.gg/angelthump/thekekinator
    

@nom-d-plume

Copy link
Copy Markdown
Contributor Author

cc @jbpratt @xDashh @slugalisk @real-salad @tensei @HoppenR @SoMuchForSubtlety @talleyp @x-Xymos — could one of you take a look? I don't have permissions to formally request reviewers on this repo.

getJSON (backing getStreamList / !strims and getProfileInfo) already
closes the response body since the Modernize refactor, but still
decodes whatever body comes back regardless of status. A non-200
response (5xx, rate limiting, WAF/edge error page, etc.) gets fed
straight into json.Decoder, producing either a confusing decode error
or, if the error body happens to be valid JSON of a different shape,
a silently empty result instead of a clear error.

Check resp.StatusCode and fail fast with a descriptive error before
decoding.
@nom-d-plume
nom-d-plume force-pushed the feature/strims-command branch from c5670a3 to f715642 Compare September 27, 2026 18:36
@nom-d-plume nom-d-plume changed the title fix: close response body and check status in getStreamList (!strims) fix: check status code before decoding getJSON responses (!strims) Sep 27, 2026
@nom-d-plume

Copy link
Copy Markdown
Contributor Author

Rebased onto master (#65 already fixed the resp.Body leak via the getJSON refactor — thanks for that). Retargeted this to the remaining gap: getJSON decoding non-200 responses without checking status code. No conflicts now.

@jbpratt
jbpratt merged commit e7369aa into MemeLabs:master Sep 27, 2026
3 checks 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.

2 participants