Skip to content

Commit

Permalink
issue #72
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtepkeev committed Feb 3, 2015
1 parent f102a54 commit 34cb6e7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
1.0.3 (2015-02-03)
++++++++++++++++++

- Fixed: `Issue #72 <https://github.com/maxtepkeev/python-redmine/issues/72>`__ (If an exception is
raised during JSON decoding process, it should be catched and reraised as Python Redmine's own
exception, i.e ``redmine.exceptions.JSONDecodeError``)
- Fixed: `Issue #76 <https://github.com/maxtepkeev/python-redmine/issues/76>`__ (It was impossible
to retrieve more than 100 resources for resources which don't support limit/offset natively by
Redmine, i.e. this functionality is emulated by Python Redmine, e.g. WikiPage, Groups, Roles etc)
Expand Down
8 changes: 6 additions & 2 deletions redmine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
ResourceNotFoundError,
RequestEntityTooLargeError,
UnknownError,
ForbiddenError
ForbiddenError,
JSONDecodeError
)


Expand Down Expand Up @@ -121,7 +122,10 @@ def request(self, method, url, headers=None, params=None, data=None, raw_respons
elif not response.content.strip():
return True
else:
return json_response(response.json)
try:
return json_response(response.json)
except (ValueError, TypeError):
raise JSONDecodeError
elif response.status_code == 401:
raise AuthError
elif response.status_code == 403:
Expand Down
6 changes: 6 additions & 0 deletions redmine/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,9 @@ class ForbiddenError(BaseRedmineError):
"""Requested resource is forbidden"""
def __init__(self):
super(ForbiddenError, self).__init__("Requested resource is forbidden")


class JSONDecodeError(BaseRedmineError):
"""Unable to decode received JSON"""
def __init__(self):
super(JSONDecodeError, self).__init__('Unable to decode received JSON, please check your server configuration')
6 changes: 6 additions & 0 deletions tests/test_redmine.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ def test_conflict_error_exception(self):
self.response.status_code = 409
self.assertRaises(ConflictError, lambda: self.redmine.request('put', self.url))

def test_json_decode_error_exception(self):
from redmine.exceptions import JSONDecodeError
self.response.status_code = 200
self.response.json = mock.Mock(side_effect=ValueError)
self.assertRaises(JSONDecodeError, lambda: self.redmine.request('get', self.url))

def test_auth_error_exception(self):
from redmine.exceptions import AuthError
self.response.status_code = 401
Expand Down

0 comments on commit 34cb6e7

Please sign in to comment.