Skip to content

Commit 61977a9

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 58117da + f38b16e commit 61977a9

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

intercom/intercom.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ def wrapper(*args, **kwargs):
4545
response = func_to_decorate(*args, **kwargs)
4646
if response.status_code == 401:
4747
raise AuthenticationError("Invalid API key/username provided.")
48-
result = json.loads(response.content)
48+
try:
49+
result = json.loads(response.content)
50+
except ValueError as err:
51+
raise ServerError(err.message)
4952
if response.status_code in (200, 201):
5053
pass
5154
else:

tests/unit/fixtures/invalid.json

Whitespace-only changes.

tests/unit/test_intercom.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,8 @@ def test_not_found(self):
7777
@patch('requests.request', create_response(500, '500.json'))
7878
def test_api_error(self):
7979
resp = Intercom.get_users()
80+
81+
@raises(ServerError)
82+
@patch('requests.request', create_response(500, 'invalid.json'))
83+
def test_api_error_when_json_is_invalid(self):
84+
Intercom.get_users()

0 commit comments

Comments
 (0)