Skip to content

Commit

Permalink
Modify return values in ApiException
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Sprague committed Feb 11, 2020
1 parent adc4180 commit 5b6edfd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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

0 comments on commit 5b6edfd

Please sign in to comment.