fix: event log UI issues and add global error toast handler

- Fix event log white background to use dark theme (bg-[#141413])
- Fix UserRole.admin typo to UserRole.ADMIN in event_detail.py
- Add global exception handler that logs errors and shows toast

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-02 09:42:26 +00:00
parent 9cd890b936
commit a1fed4ebcd
3 changed files with 11 additions and 2 deletions

View File

@@ -3,6 +3,7 @@
from __future__ import annotations from __future__ import annotations
import logging
from pathlib import Path from pathlib import Path
from fasthtml.common import Beforeware, Meta, fast_app, setup_toasts from fasthtml.common import Beforeware, Meta, fast_app, setup_toasts
@@ -19,6 +20,7 @@ from animaltrack.web.middleware import (
csrf_before, csrf_before,
request_id_before, request_id_before,
) )
from animaltrack.web.responses import error_toast
from animaltrack.web.routes import ( from animaltrack.web.routes import (
actions_router, actions_router,
animals_router, animals_router,
@@ -157,6 +159,13 @@ def create_app(
app.add_exception_handler(AuthenticationError, authentication_error_handler) app.add_exception_handler(AuthenticationError, authentication_error_handler)
app.add_exception_handler(AuthorizationError, authorization_error_handler) app.add_exception_handler(AuthorizationError, authorization_error_handler)
# Global handler for unhandled exceptions - log and show toast
async def unhandled_error_handler(request, exc):
logging.exception("Unhandled exception in %s %s", request.method, request.url.path)
return error_toast("An unexpected error occurred. Please try again.", status_code=500)
app.add_exception_handler(Exception, unhandled_error_handler)
# Register routes using APIRouter pattern # Register routes using APIRouter pattern
health_router.to_app(app) health_router.to_app(app)
actions_router.to_app(app) actions_router.to_app(app)

View File

@@ -70,7 +70,7 @@ def event_detail_panel(
# Affected animals # Affected animals
affected_animals_section(affected_animals), affected_animals_section(affected_animals),
# Delete button (admin only, not for tombstoned events) # Delete button (admin only, not for tombstoned events)
delete_section(event.id) if user_role == UserRole.admin and not is_tombstoned else None, delete_section(event.id) if user_role == UserRole.ADMIN and not is_tombstoned else None,
id="event-panel-content", id="event-panel-content",
cls="bg-[#141413] h-full overflow-y-auto", cls="bg-[#141413] h-full overflow-y-auto",
) )

View File

@@ -231,6 +231,6 @@ def event_log_panel(
event_log_list(events), event_log_list(events),
id="event-log-content", id="event-log-content",
), ),
cls="bg-white rounded-lg shadow p-4", cls="bg-[#141413] rounded-lg shadow p-4",
id="event-log", id="event-log",
) )