Skip to content

Commit 51ab98a

Browse files
committed
Add a new exception: Forbidden, when a 403 is thrown but the response is not an invalid token. This occurs when the token does not grant access to the given resource, for eg. when trying to get the warlog or current war of a clan with a private warlog
1 parent 85a28e1 commit 51ab98a

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

coc/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
NotFound,
4040
InvalidArgument,
4141
InvalidToken,
42+
Forbidden,
4243
Maitenance
4344
)
4445
from .http import HTTPClient

coc/errors.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ def __init__(self, response, message):
5555
self.response = response
5656
self.status = response.status
5757
try:
58-
self.reason = message.get('reason', '')
58+
self.reason = message.get('reason', 'Unknown')
5959
self.message = message.get('message', '')
60-
6160
except Exception:
6261
self.reason = 'Unknown'
6362
self.message = ''
@@ -81,17 +80,24 @@ class InvalidArgument(ClashOfClansException):
8180

8281

8382
class InvalidToken(HTTPException):
84-
"""Thrown when an error status 403 occurs.
85-
86-
Missing/incorrect credentials, or API token does not
87-
grant access to the requested resource.
83+
"""Thrown when an error status 403 occurs and the reason is an invalid token.
8884
85+
Special Exception thrown when missing/incorrect credentials
86+
were passed. This is most likely an invalid token.
8987
Subclass of :exc:`HTTPException`
9088
"""
9189

9290
pass
9391

9492

93+
class Forbidden(HTTPException):
94+
"""Thrown when an error status 403 occurs.
95+
96+
API token does not grant access to the requested resource.
97+
98+
Subclass of :exc:`HTTPException`"""
99+
100+
95101
class NotFound(HTTPException):
96102
"""Thrown when an error status 404 occurs.
97103

docs/api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ The following exceptions are thrown by the library.
187187

188188
.. autoexception:: InvalidToken
189189

190+
.. autoexception:: Forbidden
191+
190192
.. autoexception:: NotFound
191193

192194
.. autoexception:: Maitenance

0 commit comments

Comments
 (0)