Skip to content

fix: detect network errors from Authenticate as 503, not generic 500 - #68

Merged
jay739 merged 1 commit into
mainfrom
fix/login-network-error-shows-503-not-500
Jul 16, 2026
Merged

jay739 merged 1 commit into
mainfrom
fix/login-network-error-shows-503-not-500

Conversation

@jay739

@jay739 jay739 commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Summary

Found live testing with real credentials right after #67 deployed: login still returned a plain 500 "Jellyfin error", not the 503 #67 was supposed to produce.

Root cause: #67 only handles the case where hrfee/mediabrowser's internal panic recovery (Authenticate()'s own defer mb.timeoutHandler()) swallows a panic and returns a nil error with a zero-value user. But when Jellyfin's container is genuinely stopped (not just erroring or slow), the DNS lookup for the Jellyfin hostname fails outright — mb.httpClient.Do(req) fails at the transport level and Authenticate() returns a real, non-nil *url.Error long before it ever reaches the panic-prone line. That's a completely different, ordinary error path, not the recovered-panic case at all.

Neither ErrUnauthorized nor ErrForbidden match a network error, so it fell through to the generic 500 "Jellyfin error" branch.

Change

Detects the network-failure shape (*url.Error, which net/http.Client.Do always wraps transport-level failures in — DNS, connection refused, TLS errors) and returns 503 "Jellyfin unreachable" instead, matching the message #67 already produces for its case.

Context

This is the third attempt at getting the login-path error message right tonight (#62, then #67, now this). Each one was a real, distinct code path — #62's panic recovery genuinely can happen if Jellyfin responds with something unexpected while reachable; #67's nil-error case is real if that panic recovery swallows things silently; this PR's network-error case is what actually happens when the container is stopped, which is the scenario that's been live on batcave all night. Full incident writeup with the complete ladder is in project memory for anyone picking this up next.

Test plan

  • With Jellyfin's container fully stopped, log in with real admin credentials — confirm 503 "Jellyfin unreachable" instead of 500
  • With Jellyfin up, confirm normal login unaffected
  • CI build/test passes

Found live 2026-07-16 testing with real admin credentials against a
genuinely stopped Jellyfin container (not just slow/unreachable-but-
listening): Authenticate() returned a real, non-nil *url.Error (DNS
lookup failure for the Jellyfin hostname, since the container isn't on
the Docker network when stopped) -- a completely different code path
from #67's fix, which only handles the case where the library's
internal panic-recovery returns a nil error with a zero-value user.

Neither ErrUnauthorized nor ErrForbidden match a network error, so this
fell through to a generic 500 "Jellyfin error", which is what was
observed testing login with real credentials right after #67 deployed.

Detects the network-failure shape (*url.Error, what
net/http.Client.Do always wraps transport-level failures in) and
returns 503 "Jellyfin unreachable" instead, matching the message #67
already produces for the other failure mode.
@jay739
jay739 merged commit f6f2692 into main Jul 16, 2026
7 checks passed
@jay739
jay739 deleted the fix/login-network-error-shows-503-not-500 branch July 16, 2026 11:10
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

⌂ 换网址