jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1158607?usp=email )

Change subject: cleanup: Only use api error message and remove _api_error dict
......................................................................

cleanup: Only use api error message and remove _api_error dict

The _api_error error messages are almost wrong. Use the messages from
response which is passed to the APIEroor exception.

Change-Id: I6c394ef54aeaf735aefabfe95c78951afec937f3
---
M pywikibot/login.py
1 file changed, 3 insertions(+), 14 deletions(-)

Approvals:
  jenkins-bot: Verified
  Matěj Suchánek: Looks good to me, approved




diff --git a/pywikibot/login.py b/pywikibot/login.py
index 97bd8ff..42e41ab 100644
--- a/pywikibot/login.py
+++ b/pywikibot/login.py
@@ -287,14 +287,6 @@
                 warn('Invalid password format', _PasswordFileWarning,
                      stacklevel=2)

-    _api_error = {
-        'NotExists': 'does not exist',
-        'Illegal': 'is invalid',
-        'readapidenied': 'does not have read permissions',
-        'Failed': 'does not have read permissions',
-        'FAIL': 'does not have read permissions',
-    }
-
     def login(self, retry: bool = False, autocreate: bool = False) -> bool:
         """Attempt to log into the server.

@@ -328,12 +320,9 @@
         except APIError as e:
             error_code = e.code

-            # TODO: investigate other unhandled API codes
-            if error_code in self._api_error:
-                error_msg = (f'Username {self.login_name!r} '
-                             f'{self._api_error[error_code]} on {self.site}')
-                if error_code in ('Failed', 'FAIL'):
-                    error_msg += f'.\n{e.info}'
+            if error_code in ('NotExists', 'Illegal', 'readapidenied',
+                              'Failed', 'Aborted', 'FAIL'):
+                error_msg = f'{e.code}: {e.info}'
                 raise NoUsernameError(error_msg)

             pywikibot.error(f'Login failed ({error_code}).')

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1158607?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I6c394ef54aeaf735aefabfe95c78951afec937f3
Gerrit-Change-Number: 1158607
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to