Skip to content

Commit

Permalink
[FIX] Ensure immediate exception when login fails
Browse files Browse the repository at this point in the history
  • Loading branch information
DESm1th committed Nov 8, 2024
1 parent 0e712fc commit 31bc142
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions datman/xnat.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ def __init__(self, server, username, password):
self.auth = (username, password)
try:
self.open_session()
except Exception:
raise XnatException(f"Failed to open session with server {server}")
except Exception as e:
raise XnatException(
f"Failed to open session with server {server}. Reason - {e}")

def __enter__(self):
return self
Expand All @@ -206,6 +207,15 @@ def open_session(self):
logger.debug("Username: {}")
response.raise_for_status()

# If password is expired, XNAT returns status 200 and a sea of
# HTML causing later, unexpected, exceptions when using
# the connection. So! Check to see if we got HTML instead of a token.
if '<html' in response.text:
raise XnatException(
f"Password for user {self.auth[0]} on server {self.server} "
"has expired. Please update it."
)

# Cookies are set automatically, don't manually set them or it wipes
# out other session info
self.session = s
Expand Down

0 comments on commit 31bc142

Please sign in to comment.