about summary refs log tree commit diff
path: root/gn_auth/errors
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi <fredmanglis@gmail.com>2026-09-29 11:39:18 -0500
committerFrederick Muriuki Muriithi <fredmanglis@gmail.com>2026-09-29 11:39:18 -0500
commite06c50a97b17c3d80af6ed6874531f2c79e1b785 (patch)
treecebe068b9e7db89b80fb50793dd9f1c788b8cace /gn_auth/errors
parent7ae019865d6b7cfd39aeddf14109ece29598bb78 (diff)
downloadgn-auth-e06c50a97b17c3d80af6ed6874531f2c79e1b785.tar.gz
Do better content negotiation: prefer 'Accept' to 'Content-Type'. HEAD main
Diffstat (limited to 'gn_auth/errors')
-rw-r--r--gn_auth/errors/common.py5
1 files 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,