Skip to content

Commit d764652

Browse files
committed
Merge pull request #6 from ardeois/exception_message
`UbersmithException` returns the original `code` and `message` given by the API
2 parents 67abd3e + 8517a84 commit d764652

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

tests/api_test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@ def test_api_raises_exception_with_if_data_status_is_false(self, request_mock):
7777
ubersmith_api = ubersmith_client.api.init(self.url, self.username, self.password)
7878

7979
self.expect_a_ubersmith_call(request_mock, method="client.miss", data=data)
80-
assert_that(calling(ubersmith_api.client.miss), raises(ubersmith_client.exceptions.UbersmithException))
80+
81+
with self.assertRaises(ubersmith_client.exceptions.UbersmithException) as cm:
82+
ubersmith_api.client.miss()
83+
84+
catched_exception = cm.exception
85+
assert_that(catched_exception.code, equal_to(1))
86+
assert_that(catched_exception.message, equal_to('invalid method specified: client.miss'))
8187

8288
@requests_mock.mock()
8389
def test_api_raises_exception_for_invalid_status_code(self, request_mock):

ubersmith_client/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def process_request(self, http_method, **kwargs):
6969
response_json = response.json()
7070
if not response_json['status']:
7171
raise UbersmithException(
72-
500,
73-
"error {0}, {1}".format(response_json['error_code'], response_json['error_message'])
72+
response_json['error_code'],
73+
response_json['error_message']
7474
)
7575

7676
return response.json()["data"]

0 commit comments

Comments
 (0)