From 0d1c41f0cc27ff4338e71283563d35e4cff16c54 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Fri, 19 Apr 2024 16:36:51 +0200 Subject: [PATCH] Prefer AuthenticationRequired for credential issues --- lib/galaxy/files/sources/_pyfilesystem2.py | 7 +++++-- lib/galaxy/files/sources/_rdm.py | 4 ++-- lib/galaxy/files/sources/dropbox.py | 7 +++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/galaxy/files/sources/_pyfilesystem2.py b/lib/galaxy/files/sources/_pyfilesystem2.py index e604a6c8f75f..efdb5ac79ca8 100644 --- a/lib/galaxy/files/sources/_pyfilesystem2.py +++ b/lib/galaxy/files/sources/_pyfilesystem2.py @@ -16,7 +16,10 @@ from fs.base import FS from typing_extensions import Unpack -from galaxy.exceptions import MessageException +from galaxy.exceptions import ( + AuthenticationRequired, + MessageException, +) from . import ( BaseFilesSource, FilesSourceOptions, @@ -58,7 +61,7 @@ def _list(self, path="/", recursive=False, user_context=None, opts: Optional[Fil to_dict = functools.partial(self._resource_info_to_dict, path) return list(map(to_dict, res)) except fs.errors.PermissionDenied as e: - raise MessageException( + raise AuthenticationRequired( f"Permission Denied. Reason: {e}. Please check your credentials in your preferences for {self.label}." ) except fs.errors.FSError as e: diff --git a/lib/galaxy/files/sources/_rdm.py b/lib/galaxy/files/sources/_rdm.py index 7d9a97d2fb5f..14f7e9e1daa0 100644 --- a/lib/galaxy/files/sources/_rdm.py +++ b/lib/galaxy/files/sources/_rdm.py @@ -7,7 +7,7 @@ from typing_extensions import Unpack -from galaxy.exceptions import MessageException +from galaxy.exceptions import AuthenticationRequired from galaxy.files import ProvidesUserFileSourcesUserContext from galaxy.files.sources import ( BaseFilesSource, @@ -199,7 +199,7 @@ def get_authorization_token(self, user_context: OptionalUserContext) -> str: effective_props = self._serialization_props(user_context) token = effective_props.get("token") if not token: - raise MessageException( + raise AuthenticationRequired( f"Please provide a personal access token in your user's preferences for '{self.label}'" ) return token diff --git a/lib/galaxy/files/sources/dropbox.py b/lib/galaxy/files/sources/dropbox.py index 865338da2bbd..70c994e3e2e4 100644 --- a/lib/galaxy/files/sources/dropbox.py +++ b/lib/galaxy/files/sources/dropbox.py @@ -8,7 +8,10 @@ Union, ) -from galaxy.exceptions import MessageException +from galaxy.exceptions import ( + AuthenticationRequired, + MessageException, +) from . import ( FilesSourceOptions, FilesSourceProperties, @@ -35,7 +38,7 @@ def _open_fs(self, user_context=None, opts: Optional[FilesSourceOptions] = None) # This plugin might raise dropbox.dropbox_client.BadInputException # which is not a subclass of fs.errors.FSError if "OAuth2" in str(e): - raise MessageException( + raise AuthenticationRequired( f"Permission Denied. Reason: {e}. Please check your credentials in your preferences for {self.label}." ) raise MessageException(f"Error connecting to Dropbox. Reason: {e}")