From e06c50a97b17c3d80af6ed6874531f2c79e1b785 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 29 Sep 2026 11:39:18 -0500 Subject: Do better content negotiation: prefer 'Accept' to 'Content-Type'. --- gn_auth/errors/common.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gn_auth/errors/common.py b/gn_auth/errors/common.py index 8dc0373..35e4d21 100644 --- a/gn_auth/errors/common.py +++ b/gn_auth/errors/common.py @@ -30,10 +30,11 @@ def build_handler(description: str) -> Callable[[Exception], Response]: """Generic utility to build error handlers.""" def __handler__(exc: Exception) -> Response: """Handle the exception as appropriate for requests of different mimetypes.""" + logger.debug("EXCEPTION: %s", exc, exc_info=True) error = (exc.name if hasattr(exc, "name") else exc.__class__.__name__) status_code = __status_code__(exc) - content_type = request.content_type - if bool(content_type) and content_type.lower() == "application/json": + if ("application/json" in request.headers.get("Accept", "") + or "application/json" in request.headers.get("Content-Type", "")): return make_response(( add_trace( exc, -- cgit 1.4.1