diff options
| author | Rapptz <[email protected]> | 2015-11-27 17:03:36 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2015-11-27 17:03:36 -0500 |
| commit | b1b2c0d0997ac29b775f001f632e3327ce86509b (patch) | |
| tree | a0ede5334b307c403f84db8f732f7cd1e6c59cb7 | |
| parent | Client.edit_message no longer checks for private channel. (diff) | |
| download | discord.py-b1b2c0d0997ac29b775f001f632e3327ce86509b.tar.xz discord.py-b1b2c0d0997ac29b775f001f632e3327ce86509b.zip | |
Add LoginFailure exception for a clearer failure in Client.login
The older HTTPException is not exactly the clearest thing for people
who are new to programming or HTTP exceptions in general.
| -rw-r--r-- | discord/client.py | 7 | ||||
| -rw-r--r-- | discord/errors.py | 7 | ||||
| -rw-r--r-- | docs/api.rst | 2 |
3 files changed, 14 insertions, 2 deletions
diff --git a/discord/client.py b/discord/client.py index e182347d..203664dc 100644 --- a/discord/client.py +++ b/discord/client.py @@ -810,7 +810,7 @@ class Client(object): After this function is called, :attr:`is_logged_in` returns True if no errors occur. If an error occurs during the login process, then - :exc:`HTTPException` is raised. + :exc:`LoginFailure` or :exc:`HTTPException` is raised. This function raises :exc:`GatewayNotFound` if it was unavailable to connect to a websocket gateway. @@ -826,7 +826,10 @@ class Client(object): r = requests.post(endpoints.LOGIN, json=payload) log.debug(request_logging_format.format(response=r)) - utils._verify_successful_response(r) + if r.status_code == 400: + raise LoginFailure('Improper credentials have been passed.') + elif r.status_code != 200: + raise HTTPException(r) log.info('logging in returned status code {}'.format(r.status_code)) self.email = email diff --git a/discord/errors.py b/discord/errors.py index d105d404..abe0bff9 100644 --- a/discord/errors.py +++ b/discord/errors.py @@ -88,3 +88,10 @@ class InvalidArgument(ClientException): :exc:`DiscordException`. """ pass + +class LoginFailure(ClientException): + """Exception that's thrown when the :meth:`Client.login` function + fails to log you in from improper credentials or some other misc. + failure. + """ + pass diff --git a/docs/api.rst b/docs/api.rst index f7fcbc8f..3463e2f8 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -311,6 +311,8 @@ The following exceptions are thrown by the library. .. autoexception:: ClientException +.. autoexception:: LoginFailure + .. autoexception:: HTTPException :members: |