diff --git a/iland/exception.py b/iland/exception.py index 2358213..72cb79c 100644 --- a/iland/exception.py +++ b/iland/exception.py @@ -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): diff --git a/tests/test_iland_int.py b/tests/test_iland_int.py index f5fb839..b98f7e0 100755 --- a/tests/test_iland_int.py +++ b/tests/test_iland_int.py @@ -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