From 8c7507452a7df6d01a5ed29b242b5bee50b8192a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20L=C3=A9obal?= Date: Mon, 31 Jul 2023 19:02:55 +0200 Subject: [PATCH] Add special message on login disabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Olivier LĂ©obal --- substra/sdk/backends/remote/rest_client.py | 3 +++ substra/sdk/exceptions.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/substra/sdk/backends/remote/rest_client.py b/substra/sdk/backends/remote/rest_client.py index aabbac1d..16324c2a 100644 --- a/substra/sdk/backends/remote/rest_client.py +++ b/substra/sdk/backends/remote/rest_client.py @@ -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: diff --git a/substra/sdk/exceptions.py b/substra/sdk/exceptions.py index b247767b..80eaa3a0 100644 --- a/substra/sdk/exceptions.py +++ b/substra/sdk/exceptions.py @@ -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"""