Skip to content

Commit 92bbb7c

Browse files
committed
Add Exception InvalidCredentials
- This is thrown when invalid credentials are passed. This is usually an incorrect email/password pair. - Subclass of `HTTPException`
1 parent 2fd2587 commit 92bbb7c

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

coc/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@
3838
HTTPException,
3939
NotFound,
4040
InvalidArgument,
41-
InvalidToken,
41+
InvalidCredentials,
4242
Forbidden,
4343
Maitenance
4444
)
4545
from .http import HTTPClient
46+
47+
from .enums import (
48+
CacheType
49+
)

coc/errors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ class InvalidArgument(ClashOfClansException):
7979
pass
8080

8181

82-
class InvalidToken(HTTPException):
83-
"""Thrown when an error status 403 occurs and the reason is an invalid token.
82+
class InvalidCredentials(HTTPException):
83+
"""Thrown when an error status 403 occurs and the reason is invalid credentials.
8484
8585
Special Exception thrown when missing/incorrect credentials
86-
were passed. This is most likely an invalid token.
86+
were passed. This is when your email/password pair is incorrect.
8787
Subclass of :exc:`HTTPException`
8888
"""
8989

coc/http.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from datetime import datetime
4040
from collections import deque
4141

42-
from .errors import HTTPException, Maitenance, NotFound, InvalidArgument, Forbidden
42+
from .errors import HTTPException, Maitenance, NotFound, InvalidArgument, Forbidden, InvalidCredentials
4343

4444
log = logging.getLogger(__name__)
4545
KEY_MINIMUM, KEY_MAXIMUM = 1, 10
@@ -366,6 +366,8 @@ async def login_to_site(self, email, password):
366366
response_dict = await sess.json()
367367
log.debug('%s has received %s', 'https://developer.clashofclans.com/api/login',
368368
response_dict)
369+
if sess.status == 403:
370+
raise InvalidCredentials(sess, response_dict)
369371

370372
session = sess.cookies.get('session').value
371373

docs/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ The following exceptions are thrown by the library.
212212

213213
.. autoexception:: InvalidArgument
214214

215-
.. autoexception:: InvalidToken
215+
.. autoexception:: InvalidCredentials
216216

217217
.. autoexception:: Forbidden
218218

0 commit comments

Comments
 (0)