Skip to content

Return graceful output from get_stats instead of a 500#1570

Merged
KodeStar merged 2 commits into
2.xfrom
fix/getstats-graceful-failure
Jul 8, 2026
Merged

Return graceful output from get_stats instead of a 500#1570
KodeStar merged 2 commits into
2.xfrom
fix/getstats-graceful-failure

Conversation

@KodeStar

@KodeStar KodeStar commented Jul 8, 2026

Copy link
Copy Markdown
Member

Problem

Resolves #1558.

GET get_stats/{id} returned HTTP 500 when an enhanced app's live-stats rendering failed — the reporter's Komga tile. Two causes: Item::find($id) fataled on a missing id, and $application->livestats() threw whenever a remote app definition was broken/updated or its upstream API returned unexpected data.

Because the frontend (liveStatRefresh.js) stops re-queuing a tile on any non-200 response, a single 500 also permanently killed that tile's live updates until a page reload.

The individual app definitions (Komga, etc.) live in a separate remote repo downloaded to app/SupportedApps/ at runtime, so their blades can't be fixed here — but the core endpoint should never 500 on a bad one.

Change

ItemController::getStats now always returns valid JSON (HTTP 200):

  • missing item, no class, or a stale/renamed class string → {"status":"inactive","html":""}
  • any \Throwable from config/instantiation/livestats() is caught, logged (id + class + message), and returns the same graceful payload
  • the success path is unchanged — the raw livestats() JSON is returned verbatim

The tile renders empty on failure and the refresh loop keeps running, instead of the whole request 500ing.

Tests

tests/Feature/GetStatsTest.php (4 tests): missing id doesn't 500, a throwing app degrades gracefully (the #1558 regression), an item with no class is graceful, and the happy path returns livestats output byte-for-byte. Full suite green; phpcs no new errors.

get_stats/{id} fataled when the item id was missing and 500'd whenever an
enhanced app's livestats() threw - a broken or updated remote app definition
(e.g. Komga) took the whole request down, and the frontend then stopped
refreshing that tile entirely.

getStats now returns valid JSON (200) with an inactive/empty payload when the
item is missing, has no class, references a stale class, or throws, logging
the failure for diagnosis. The successful path is unchanged and returns the
livestats output verbatim.

Resolves #1558
@KodeStar KodeStar merged commit 0763484 into 2.x Jul 8, 2026
1 check passed
@LinuxServer-CI LinuxServer-CI moved this from PRs to Done in Issue & PR Tracker Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Komga app stats not working (error 500)

2 participants