fix(setup,ui): risolve errori setup + logo SVG theme-aware

- setup: corregge path templates (sibling di api/, non figlio) e firma TemplateResponse
- setup: invalida sessione client dopo operazioni che ruotano l'API key (init DB, creazione admin, cambio password, attivazione utente)
- api_client: include il nome del campo nei messaggi di errore 422 (FastAPI validation)
- ui: nuovo componente _app_logo.html (SVG inline theme-aware) usato su login e navbar
This commit is contained in:
Adriano Dal Pastro
2026-05-20 07:42:49 +00:00
parent 182aa9fa9a
commit 6772e3166a
6 changed files with 80 additions and 19 deletions
+14 -4
View File
@@ -56,11 +56,21 @@ class APIClient:
try:
error_body = response.json()
detail = error_body.get("detail", str(error_body))
# FastAPI 422 returns detail as a list of validation errors
# FastAPI 422 returns detail as a list of validation errors:
# [{"type": ..., "loc": ["body", "password"], "msg": "...", ...}, ...]
if isinstance(detail, list):
detail = "; ".join(
e.get("msg", str(e)) for e in detail if isinstance(e, dict)
) or str(detail)
parts = []
for e in detail:
if not isinstance(e, dict):
parts.append(str(e))
continue
msg = e.get("msg", str(e))
loc = e.get("loc") or []
# Strip leading "body"/"query"/"path" segments; keep field path.
field_path = [str(p) for p in loc if p not in ("body", "query", "path")]
field = ".".join(field_path) if field_path else None
parts.append(f"{field}: {msg}" if field else msg)
detail = "; ".join(parts) or str(detail)
except Exception:
detail = response.text or f"HTTP {response.status_code}"