Skip to content

Add support for token_unauthorized error. #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion intercom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
7 changes: 6 additions & 1 deletion intercom/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class UnexpectedError(IntercomError):
pass


class TokenUnauthorizedError(IntercomError):
pass


error_codes = {
'unauthorized': AuthenticationError,
'forbidden': AuthenticationError,
Expand All @@ -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
}
18 changes: 18 additions & 0 deletions tests/unit/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down