diff --git a/intercom/__init__.py b/intercom/__init__.py index 0cb56385..ea919d39 100644 --- a/intercom/__init__.py +++ b/intercom/__init__.py @@ -4,7 +4,7 @@ from .errors import (ArgumentError, AuthenticationError, # noqa BadGatewayError, BadRequestError, HttpError, IntercomError, MultipleMatchingUsersError, RateLimitExceeded, ResourceNotFound, - ServerError, ServiceUnavailableError, UnexpectedError) + ServerError, ServiceUnavailableError, UnexpectedError, TokenUnauthorizedError) __version__ = '3.0b2' diff --git a/intercom/errors.py b/intercom/errors.py index cf34b0d5..33272dc1 100644 --- a/intercom/errors.py +++ b/intercom/errors.py @@ -53,6 +53,10 @@ class UnexpectedError(IntercomError): pass +class TokenUnauthorizedError(IntercomError): + pass + + error_codes = { 'unauthorized': AuthenticationError, 'forbidden': AuthenticationError, @@ -65,5 +69,6 @@ class UnexpectedError(IntercomError): 'rate_limit_exceeded': RateLimitExceeded, 'service_unavailable': ServiceUnavailableError, 'conflict': MultipleMatchingUsersError, - 'unique_user_constraint': MultipleMatchingUsersError + 'unique_user_constraint': MultipleMatchingUsersError, + 'token_unauthorized': TokenUnauthorizedError } diff --git a/tests/unit/test_request.py b/tests/unit/test_request.py index 5b14d2e6..09beaf07 100644 --- a/tests/unit/test_request.py +++ b/tests/unit/test_request.py @@ -233,6 +233,24 @@ def it_raises_a_multiple_matching_users_error(self): with assert_raises(intercom.MultipleMatchingUsersError): self.client.get('/users', {}) + @istest + def it_raises_token_unauthorized(self): + payload = { + 'type': 'error.list', + 'errors': [ + { + 'type': 'token_unauthorized', + 'message': 'The PAT is not authorized for this action.' + } + ] + } + content = json.dumps(payload).encode('utf-8') + resp = mock_response(content) + with patch('requests.request') as mock_method: + mock_method.return_value = resp + with assert_raises(intercom.TokenUnauthorizedError): + self.client.get('/users', {}) + @istest def it_handles_no_error_type(self): payload = {