From a1fed4ebcdbbb824d91ffbe327c0dd84aba7dcda Mon Sep 17 00:00:00 2001 From: Petru Paler Date: Fri, 2 Jan 2026 09:42:26 +0000 Subject: [PATCH] fix: event log UI issues and add global error toast handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- src/animaltrack/web/app.py | 9 +++++++++ src/animaltrack/web/templates/event_detail.py | 2 +- src/animaltrack/web/templates/events.py | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/animaltrack/web/app.py b/src/animaltrack/web/app.py index f4107b9..dc8a2eb 100644 --- a/src/animaltrack/web/app.py +++ b/src/animaltrack/web/app.py @@ -3,6 +3,7 @@ from __future__ import annotations +import logging from pathlib import Path from fasthtml.common import Beforeware, Meta, fast_app, setup_toasts @@ -19,6 +20,7 @@ from animaltrack.web.middleware import ( csrf_before, request_id_before, ) +from animaltrack.web.responses import error_toast from animaltrack.web.routes import ( actions_router, animals_router, @@ -157,6 +159,13 @@ def create_app( app.add_exception_handler(AuthenticationError, authentication_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 health_router.to_app(app) actions_router.to_app(app) diff --git a/src/animaltrack/web/templates/event_detail.py b/src/animaltrack/web/templates/event_detail.py index ddcc5c4..4f4c11f 100644 --- a/src/animaltrack/web/templates/event_detail.py +++ b/src/animaltrack/web/templates/event_detail.py @@ -70,7 +70,7 @@ def event_detail_panel( # Affected animals affected_animals_section(affected_animals), # 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", cls="bg-[#141413] h-full overflow-y-auto", ) diff --git a/src/animaltrack/web/templates/events.py b/src/animaltrack/web/templates/events.py index 1c6ee20..1ae834d 100644 --- a/src/animaltrack/web/templates/events.py +++ b/src/animaltrack/web/templates/events.py @@ -231,6 +231,6 @@ def event_log_panel( event_log_list(events), id="event-log-content", ), - cls="bg-white rounded-lg shadow p-4", + cls="bg-[#141413] rounded-lg shadow p-4", id="event-log", )