about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--gn_auth/auth/authorisation/resources/views.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/gn_auth/auth/authorisation/resources/views.py b/gn_auth/auth/authorisation/resources/views.py
index 2737916..3cc2404 100644
--- a/gn_auth/auth/authorisation/resources/views.py
+++ b/gn_auth/auth/authorisation/resources/views.py
@@ -534,13 +534,21 @@ def resources_authorisation():
                 } for resid in resource_ids
             })
     except _HTTPException as _httpe:
-        err_msg = json.loads(_httpe.body)
-        if err_msg["error"] == "missing_authorization":
-            resp = jsonify({
-                str(resid): {
-                    "public-read": resid in pubres
-                } for resid in resource_ids
-            })
+        # Any token-related failure here -- missing header, malformed
+        # token, expired token, etc. -- degrades to the same
+        # public-only view, not just the "no header at all"
+        # (missing_authorization) case. Without this, an invalid
+        # bearer token (error "invalid_token", not
+        # "missing_authorization") left `resp` unset below, raising
+        # UnboundLocalError instead of the graceful anonymous fallback
+        # this endpoint is documented to provide.
+        logger.debug("Token-related exception, falling back to public-only "
+                     "view.", exc_info=True)
+        resp = jsonify({
+            str(resid): {
+                "public-read": resid in pubres
+            } for resid in resource_ids
+        })
     except AssertionError as _aerr:
         resp = jsonify({
             "status": "bad-request",