Skip to content

Commit

Permalink
Add special message on login disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Léobal <[email protected]>
  • Loading branch information
oleobal committed Jul 31, 2023
1 parent 90cf9e0 commit 8c75074
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions substra/sdk/backends/remote/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def login(self, username, password):
if e.response.status_code in (400, 401):
raise exceptions.BadLoginException.from_request_exception(e)

if e.response.status_code == 410:
raise exceptions.UsernamePasswordLoginDisabledException.from_request_exception(e)

raise exceptions.HTTPError.from_request_exception(e)

try:
Expand Down
18 changes: 18 additions & 0 deletions substra/sdk/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ class BadLoginException(RequestException):
pass


class UsernamePasswordLoginDisabledException(RequestException):
"""The server disabled the endpoint, preventing the use of Client.login"""

@classmethod
def from_request_exception(cls, request_exception):
base = super().from_request_exception(request_exception)
return cls(
base.msg
+ (
"\n\nAuthenticating with username/password is disabled.\n"
"Log onto the frontend for your instance and generate a token there, "
'then use it in the Client(token="...") constructor: '
"https://docs.substra.org/en/stable/documentation/api_tokens_generation.html"
),
base.status_code,
)


class ConfigurationInfoError(SDKException):
"""ConfigurationInfoError"""

Expand Down

0 comments on commit 8c75074

Please sign in to comment.