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.
This commit is contained in:
parent
f83442096b
commit
b1b2c0d099
@ -810,7 +810,7 @@ class Client(object):
|
|||||||
|
|
||||||
After this function is called, :attr:`is_logged_in` returns True if no
|
After this function is called, :attr:`is_logged_in` returns True if no
|
||||||
errors occur. If an error occurs during the login process, then
|
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
|
This function raises :exc:`GatewayNotFound` if it was unavailable to connect
|
||||||
to a websocket gateway.
|
to a websocket gateway.
|
||||||
@ -826,7 +826,10 @@ class Client(object):
|
|||||||
|
|
||||||
r = requests.post(endpoints.LOGIN, json=payload)
|
r = requests.post(endpoints.LOGIN, json=payload)
|
||||||
log.debug(request_logging_format.format(response=r))
|
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))
|
log.info('logging in returned status code {}'.format(r.status_code))
|
||||||
self.email = email
|
self.email = email
|
||||||
|
@ -88,3 +88,10 @@ class InvalidArgument(ClientException):
|
|||||||
:exc:`DiscordException`.
|
:exc:`DiscordException`.
|
||||||
"""
|
"""
|
||||||
pass
|
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
|
||||||
|
@ -311,6 +311,8 @@ The following exceptions are thrown by the library.
|
|||||||
|
|
||||||
.. autoexception:: ClientException
|
.. autoexception:: ClientException
|
||||||
|
|
||||||
|
.. autoexception:: LoginFailure
|
||||||
|
|
||||||
.. autoexception:: HTTPException
|
.. autoexception:: HTTPException
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user