From 8f4104a4bfb2595c051f38d62a9ef58a48303368 Mon Sep 17 00:00:00 2001 From: giles Date: Wed, 25 Feb 2026 03:18:06 +0000 Subject: [PATCH] Add error handling to action endpoint dispatchers Unhandled exceptions in action handlers were returned as opaque 400/500 by Quart's default error handler. Now we catch, log the full traceback, and return a JSON error body with 500 status so the caller gets useful diagnostics. Co-Authored-By: Claude Opus 4.6 --- cart/bp/actions/routes.py | 9 +++++++-- events/bp/actions/routes.py | 9 +++++++-- market/bp/actions/routes.py | 9 +++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cart/bp/actions/routes.py b/cart/bp/actions/routes.py index 3a33248..d6a2be9 100644 --- a/cart/bp/actions/routes.py +++ b/cart/bp/actions/routes.py @@ -26,8 +26,13 @@ def register() -> Blueprint: handler = _handlers.get(action_name) if handler is None: return jsonify({"error": "unknown action"}), 404 - result = await handler() - return jsonify(result) + try: + result = await handler() + return jsonify(result) + except Exception as exc: + import logging + logging.getLogger(__name__).exception("Action %s failed", action_name) + return jsonify({"error": str(exc)}), 500 # --- adopt-cart-for-user --- async def _adopt_cart(): diff --git a/events/bp/actions/routes.py b/events/bp/actions/routes.py index c67f1dd..921c8b0 100644 --- a/events/bp/actions/routes.py +++ b/events/bp/actions/routes.py @@ -26,8 +26,13 @@ def register() -> Blueprint: handler = _handlers.get(action_name) if handler is None: return jsonify({"error": "unknown action"}), 404 - result = await handler() - return jsonify(result) + try: + result = await handler() + return jsonify(result) + except Exception as exc: + import logging + logging.getLogger(__name__).exception("Action %s failed", action_name) + return jsonify({"error": str(exc)}), 500 # --- adjust-ticket-quantity --- async def _adjust_ticket_quantity(): diff --git a/market/bp/actions/routes.py b/market/bp/actions/routes.py index f7e1f0b..f4034eb 100644 --- a/market/bp/actions/routes.py +++ b/market/bp/actions/routes.py @@ -26,8 +26,13 @@ def register() -> Blueprint: handler = _handlers.get(action_name) if handler is None: return jsonify({"error": "unknown action"}), 404 - result = await handler() - return jsonify(result) + try: + result = await handler() + return jsonify(result) + except Exception as exc: + import logging + logging.getLogger(__name__).exception("Action %s failed", action_name) + return jsonify({"error": str(exc)}), 500 # --- create-marketplace --- async def _create_marketplace():