Skip to content

fix(connectors): narrow broad except in tokens.py 401-handling (No-Silent-Fallbacks) #1612

@itomek

Description

@itomek

Why

PR #1599 (#1592) added 401-handling in _refresh_token (src/gaia/connectors/tokens.py, ~lines 214–216) that parses the OAuth error payload with a broad swallow:

try:
    err_payload = response.json()
except Exception:
    err_payload = {}

This violates CLAUDE.md's "No Silent Fallbacks" rule (a handler that discards the error and returns a placeholder). If response.json() raises something unexpected (e.g. an AttributeError on a mock, or a non-JSON body throwing something other than a decode error), the payload silently collapses to {} and the user-facing message at tokens.py:231 always reports invalid_client — hiding the real cause.

Flagged in the PR #1599 review (github-actions bot) but the PR merged before it was addressed, so the violation is now in main.

Fix

Narrow the handler — httpx's .json() only raises json.JSONDecodeError (a ValueError subclass) on a malformed body, so this is sufficient and lets any genuine programming error surface:

try:
    err_payload = response.json()
except (ValueError, json.JSONDecodeError):
    err_payload = {}

(Confirm json is imported in tokens.py.)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions