~150 HTTPExceptions carried a hand-written English sentence as their detail,
shown verbatim under the Hungarian UI — in the blocking error dialog and on
every inline surface that printed HttpError.detail (sign-in, setup wizard,
change password, the passphrase gate, live search). Four also quoted an
upstream exception's text back to the user.
- app/refusal.py: `refused(status, reason, **params)` → {code: "refused",
reason, …params}; localizeDetail translates errors.refused.<reason> with the
params interpolated. "Unknown X" 404s use the existing not_found(what).
- sysconfig.set_value raises InvalidSetting (reason + bounds) instead of an
English ValueError; the three writers answer it through setting_refused.
- The Plex connection/write/image failures log what the upstream said and
answer a reason; the search scraper's failure is logged and answered as
youtube/unavailable (it crashed refusal_reason before).
- HttpError.detail now only ever holds a translated reason: a string detail
(only the framework's own can remain) is left out, so reading .detail is
safe everywhere — including destructured, the hole the raw-detail source
scan could not see. That scan and its five-file exception list are gone.
- Enforced: test_http_details.py fails on any HTTPException with a sentence
for a detail; the contract test requires every refused reason and every
not_found "what" in both languages, and no key for one that is gone.
- local/jsx-comment-text: a // inside JSX children renders as text; the rule
is ten lines in eslint.config.js rather than eslint-plugin-react's ~1800
lockfile lines.
23 lines
644 B
Python
23 lines
644 B
Python
"""Shared helpers, serializers and constants for the plex route package."""
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app import logs
|
|
from app.models import PlexItem
|
|
from app.plex.lookups import by_rating_key
|
|
from app.routes._common import not_found
|
|
|
|
log = logs.get_logger(__name__)
|
|
|
|
|
|
def item_or_404(db: Session, rating_key: str) -> PlexItem:
|
|
it = by_rating_key(db, PlexItem, rating_key)
|
|
if it is None:
|
|
raise not_found("plex_item")
|
|
return it
|
|
|
|
|
|
def _norm_lang(lang: str | None) -> str:
|
|
"""The overlay has an EN base + an optional HU twin; anything other than `hu` serves EN."""
|
|
return "hu" if lang == "hu" else "en"
|