Skip to content

Commit 43a7189

Browse files
authored
Merge pull request #134 from jkeyes/token-unauthorized
Add support for token_unauthorized error.
2 parents 98c3e78 + 45593e4 commit 43a7189

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

intercom/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .errors import (ArgumentError, AuthenticationError, # noqa
55
BadGatewayError, BadRequestError, HttpError, IntercomError,
66
MultipleMatchingUsersError, RateLimitExceeded, ResourceNotFound,
7-
ServerError, ServiceUnavailableError, UnexpectedError)
7+
ServerError, ServiceUnavailableError, UnexpectedError, TokenUnauthorizedError)
88

99
__version__ = '3.0b2'
1010

intercom/errors.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class UnexpectedError(IntercomError):
5353
pass
5454

5555

56+
class TokenUnauthorizedError(IntercomError):
57+
pass
58+
59+
5660
error_codes = {
5761
'unauthorized': AuthenticationError,
5862
'forbidden': AuthenticationError,
@@ -65,5 +69,6 @@ class UnexpectedError(IntercomError):
6569
'rate_limit_exceeded': RateLimitExceeded,
6670
'service_unavailable': ServiceUnavailableError,
6771
'conflict': MultipleMatchingUsersError,
68-
'unique_user_constraint': MultipleMatchingUsersError
72+
'unique_user_constraint': MultipleMatchingUsersError,
73+
'token_unauthorized': TokenUnauthorizedError
6974
}

tests/unit/test_request.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,24 @@ def it_raises_a_multiple_matching_users_error(self):
233233
with assert_raises(intercom.MultipleMatchingUsersError):
234234
self.client.get('/users', {})
235235

236+
@istest
237+
def it_raises_token_unauthorized(self):
238+
payload = {
239+
'type': 'error.list',
240+
'errors': [
241+
{
242+
'type': 'token_unauthorized',
243+
'message': 'The PAT is not authorized for this action.'
244+
}
245+
]
246+
}
247+
content = json.dumps(payload).encode('utf-8')
248+
resp = mock_response(content)
249+
with patch('requests.request') as mock_method:
250+
mock_method.return_value = resp
251+
with assert_raises(intercom.TokenUnauthorizedError):
252+
self.client.get('/users', {})
253+
236254
@istest
237255
def it_handles_no_error_type(self):
238256
payload = {

0 commit comments

Comments
 (0)