Skip to content

Commit 595910c

Browse files
author
Andrew Sprague
committed
Modify return values in ApiException
1 parent adc4180 commit 595910c

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

docs/iland.rst

+15-15
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,39 @@ iland.api module
88
----------------
99

1010
.. automodule:: iland.api
11-
:members:
12-
:undoc-members:
13-
:show-inheritance:
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
1414

1515
iland.constant module
1616
---------------------
1717

1818
.. automodule:: iland.constant
19-
:members:
20-
:undoc-members:
21-
:show-inheritance:
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
2222

2323
iland.exception module
2424
----------------------
2525

2626
.. automodule:: iland.exception
27-
:members:
28-
:undoc-members:
29-
:show-inheritance:
27+
:members:
28+
:undoc-members:
29+
:show-inheritance:
3030

3131
iland.log module
3232
----------------
3333

3434
.. automodule:: iland.log
35-
:members:
36-
:undoc-members:
37-
:show-inheritance:
35+
:members:
36+
:undoc-members:
37+
:show-inheritance:
3838

3939

4040
Module contents
4141
---------------
4242

4343
.. automodule:: iland
44-
:members:
45-
:undoc-members:
46-
:show-inheritance:
44+
:members:
45+
:undoc-members:
46+
:show-inheritance:

iland/api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
import requests
99

10-
from .constant import BASE_URL, ACCESS_URL, REFRESH_URL
11-
from .log import LOG
10+
from .constant import ACCESS_URL, BASE_URL, REFRESH_URL
1211
from .exception import ApiException, UnauthorizedException
12+
from .log import LOG
1313

1414

1515
class Api(object):

iland/exception.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ class ApiException(Exception):
99
@property
1010
def error(self):
1111
"""Returns the first argument used to construct this error."""
12-
return self.args[0]
12+
return self.args[0].get('type')
1313

1414
@property
1515
def message(self):
1616
"""Returns the second argument used to construct this error."""
17-
return self.args[1]
17+
return self.args[0].get('message')
1818

1919
@property
2020
def detail_message(self):
2121
"""Returns the third argument used to construct this error."""
22-
return self.args[2]
22+
return self.args[0].get('detail_message')
2323

2424

2525
class UnauthorizedException(ApiException):

tests/test_iland.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import time
77
import unittest
88

9-
import requests_mock
10-
119
import iland
1210

11+
import requests_mock
12+
1313
BASE_URL = 'http://example.com/ecs'
1414

1515
VALID_TOKEN_PAYLOAD = {'expires_in': 12,

tests/test_iland_int.py

+11
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ def test_api_errors(self):
143143
with self.assertRaises(ApiException):
144144
self._api.get('/doesnotexist')
145145

146+
def test_api_exception_properties(self):
147+
with self.assertRaises(ApiException) as e:
148+
self._api.get('/doesnotexist')
149+
api_exception = e.exception
150+
self.assertEqual(api_exception.error,
151+
'NotFoundError')
152+
self.assertEqual(api_exception.message,
153+
'The specified resource does not exist.')
154+
self.assertIn('Could not find resource for full path',
155+
api_exception.detail_message)
156+
146157
@unittest.skipIf(not PROXIES, "No proxies defined")
147158
def test_get_with_proxy(self):
148159
self._api._proxies = PROXIES

0 commit comments

Comments
 (0)