Skip to content

Commit 34cb6e7

Browse files
committed
issue #72
1 parent f102a54 commit 34cb6e7

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Changelog
44
1.0.3 (2015-02-03)
55
++++++++++++++++++
66

7+
- Fixed: `Issue #72 <https://github.com/maxtepkeev/python-redmine/issues/72>`__ (If an exception is
8+
raised during JSON decoding process, it should be catched and reraised as Python Redmine's own
9+
exception, i.e ``redmine.exceptions.JSONDecodeError``)
710
- Fixed: `Issue #76 <https://github.com/maxtepkeev/python-redmine/issues/76>`__ (It was impossible
811
to retrieve more than 100 resources for resources which don't support limit/offset natively by
912
Redmine, i.e. this functionality is emulated by Python Redmine, e.g. WikiPage, Groups, Roles etc)

redmine/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
ResourceNotFoundError,
1818
RequestEntityTooLargeError,
1919
UnknownError,
20-
ForbiddenError
20+
ForbiddenError,
21+
JSONDecodeError
2122
)
2223

2324

@@ -121,7 +122,10 @@ def request(self, method, url, headers=None, params=None, data=None, raw_respons
121122
elif not response.content.strip():
122123
return True
123124
else:
124-
return json_response(response.json)
125+
try:
126+
return json_response(response.json)
127+
except (ValueError, TypeError):
128+
raise JSONDecodeError
125129
elif response.status_code == 401:
126130
raise AuthError
127131
elif response.status_code == 403:

redmine/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,9 @@ class ForbiddenError(BaseRedmineError):
162162
"""Requested resource is forbidden"""
163163
def __init__(self):
164164
super(ForbiddenError, self).__init__("Requested resource is forbidden")
165+
166+
167+
class JSONDecodeError(BaseRedmineError):
168+
"""Unable to decode received JSON"""
169+
def __init__(self):
170+
super(JSONDecodeError, self).__init__('Unable to decode received JSON, please check your server configuration')

tests/test_redmine.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ def test_conflict_error_exception(self):
115115
self.response.status_code = 409
116116
self.assertRaises(ConflictError, lambda: self.redmine.request('put', self.url))
117117

118+
def test_json_decode_error_exception(self):
119+
from redmine.exceptions import JSONDecodeError
120+
self.response.status_code = 200
121+
self.response.json = mock.Mock(side_effect=ValueError)
122+
self.assertRaises(JSONDecodeError, lambda: self.redmine.request('get', self.url))
123+
118124
def test_auth_error_exception(self):
119125
from redmine.exceptions import AuthError
120126
self.response.status_code = 401

0 commit comments

Comments
 (0)