fix(kuma-bridge): a rejected login is not-ready (was falsely 'up'); clearer connect vs login errors
Verified with a reachable Kuma and deliberately wrong credentials: /ready -> 503 'Kuma login rejected: Incorrect username or password.' Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>feat/portal-design
parent
353df9f054
commit
d1db23398d
|
|
@ -60,7 +60,9 @@ def _connect() -> UptimeKumaApi:
|
|||
api.disconnect()
|
||||
except Exception: # noqa: BLE001, S110
|
||||
pass
|
||||
raise HTTPException(status_code=503, detail=f"Kuma unreachable: {exc}") from exc
|
||||
# Distinguish "cannot reach" from "rejected us" — very different fixes.
|
||||
kind = "login rejected" if "username or password" in str(exc).lower() else "unreachable"
|
||||
raise HTTPException(status_code=503, detail=f"Kuma {kind}: {exc}") from exc
|
||||
_api = api
|
||||
|
||||
return _api
|
||||
|
|
@ -151,15 +153,18 @@ def _kuma_state() -> tuple[str, str | None]:
|
|||
except Exception as exc: # noqa: BLE001 — connection refused/DNS/timeout
|
||||
return "down", f"HTTP unreachable: {exc}"
|
||||
|
||||
# An authenticated, connected session is the real proof: _connect() performs
|
||||
# the login round-trip, so bad credentials / missing 2FA / an incompatible
|
||||
# login API all surface here as "down" rather than a false "up".
|
||||
try:
|
||||
_call(lambda api: _require_live(api) and api.get_monitor_status(0))
|
||||
with _lock:
|
||||
api = _connect()
|
||||
if not getattr(api, "sio", None) or not api.sio.connected:
|
||||
_reset()
|
||||
return "down", "Kuma socket not connected"
|
||||
return "up", None
|
||||
except HTTPException as exc:
|
||||
# A live call on a bogus id may error while the session is fine — the
|
||||
# socket being connected is what we actually care about here.
|
||||
if "not connected" in str(exc.detail):
|
||||
return "down", str(exc.detail)
|
||||
return "up", None
|
||||
except Exception as exc: # noqa: BLE001 — must never 500
|
||||
return "down", str(exc)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue