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", )