Skip to content
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

Modify return values in ApiException #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions iland/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ class ApiException(Exception):
@property
def error(self):
"""Returns the first argument used to construct this error."""
return self.args[0]
return self.args[0].get('type')

@property
def message(self):
"""Returns the second argument used to construct this error."""
return self.args[1]
return self.args[0].get('message')

@property
def detail_message(self):
"""Returns the third argument used to construct this error."""
return self.args[2]
return self.args[0].get('detail_message')


class UnauthorizedException(ApiException):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_iland_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ def test_api_errors(self):
with self.assertRaises(ApiException):
self._api.get('/doesnotexist')

def test_api_exception_properties(self):
with self.assertRaises(ApiException) as e:
self._api.get('/doesnotexist')
api_exception = e.exception
self.assertEqual(api_exception.error,
'NotFoundError')
self.assertEqual(api_exception.message,
'The specified resource does not exist.')
self.assertIn('Could not find resource for full path',
api_exception.detail_message)

@unittest.skipIf(not PROXIES, "No proxies defined")
def test_get_with_proxy(self):
self._api._proxies = PROXIES
Expand Down