Skip to content

Stop reporting auth-service failures as invalid tokens - #211

Merged
rbardaji merged 1 commit into
mainfrom
fix/195-auth-error-status
Jul 27, 2026
Merged

Stop reporting auth-service failures as invalid tokens#211
rbardaji merged 1 commit into
mainfrom
fix/195-auth-error-status

Conversation

@rbardaji

Copy link
Copy Markdown
Collaborator

Closes #195

Problem

get_current_user raised HTTPException(502) for an unreachable or misbehaving authentication service inside a try whose trailing except Exception rewrote everything as 401 "Authentication failed". Since HTTPException is an Exception, those deliberate 502s were caught and flattened — so an auth service that was down, returning 500, or answering an unexpected status looked exactly like a mistyped token.

This cost real diagnosis time earlier: the AAI returned 500 for a token without a sub claim, and the UI reported invalid credentials.

Fix

  • except HTTPException: raise before the generic handler, so deliberately-raised statuses reach the caller unchanged.
  • An unreachable service (RequestException) and unexpected internal errors return 502, not 401.
  • A response body carrying an error field is a real token rejection → 401 with a clear message.
  • A genuinely invalid token still returns 401.

Verified

New tests/test_get_current_user_errors.py: auth-service 500 / unexpected status / unreachable all return 502; invalid token and error-in-body return 401; a valid token returns the user info. Full suite 1176 passed; black/flake8 clean.

get_current_user raised HTTPException(502) for an unreachable or
misbehaving authentication service inside a try whose trailing
'except Exception' rewrote everything as 401 'Authentication failed'.
Since HTTPException is an Exception, those deliberate 502s were caught
and flattened, so an auth service that was down — or returning 500, or an
unexpected status — looked exactly like a mistyped token. That cost real
diagnosis time when the AAI returned 500 for a token without a sub claim.

Deliberately-raised statuses now propagate unchanged (except HTTPException:
raise). An unreachable service and unexpected internal errors return 502.
A response body carrying an error field is a real token rejection, so it
returns 401. A genuinely invalid token still returns 401.

Closes #195
@rbardaji
rbardaji merged commit 80f9571 into main Jul 27, 2026
1 check passed
@rbardaji
rbardaji deleted the fix/195-auth-error-status branch July 27, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Authentication errors are reported as invalid tokens

1 participant