Skip to content

Commit 7a37483

Browse files
committed
Adding separate exception for http error. Inherits from ApiMetaError
which ApiError also inherits from. rename ApiMetaError to ApiBaseError
1 parent c6ab8ac commit 7a37483

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

betfair/exceptions.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,31 @@ def __init__(self, response, data):
2727
super(AuthError, self).__init__(self.message)
2828

2929

30-
class ApiError(BetfairError):
30+
class ApiBaseError(BetfairError):
3131

32-
def __init__(self, response, data):
32+
def __init__(self, response, message, details):
3333
self.response = response
3434
self.status_code = response.status_code
35+
self.message = message
36+
self.details = details
37+
super(ApiBaseError, self).__init__(self.message)
38+
39+
40+
class ApiError(ApiBaseError):
41+
42+
def __init__(self, response, data):
3543
try:
3644
error_data = data['error']['data']['APINGException']
37-
self.message = error_data.get('errorCode', 'UNKNOWN')
38-
self.details = error_data.get('errorDetails')
45+
message = error_data.get('errorCode', 'UNKNOWN')
46+
details = error_data.get('errorDetails')
3947
except KeyError:
40-
self.message = 'UNKNOWN'
41-
self.details = None
42-
super(ApiError, self).__init__(self.message)
48+
message = 'UNKNOWN'
49+
details = None
50+
super(ApiError, self).__init__(response, message, details)
51+
52+
53+
class ApiHttpError(ApiBaseError):
54+
55+
def __init__(self, response):
56+
super(ApiHttpError, self).__init__(response, "error http return code: %s" %
57+
response.status_code, None)

betfair/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def check_status_code(response, codes=None):
5353
else lambda resp: resp.status_code in codes
5454
)
5555
if not checker(response):
56-
raise exceptions.ApiError(response, response.json())
56+
raise exceptions.ApiHttpError(response)
5757

5858

5959
def result_or_error(response):

tests/test_betfair.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ def test_login_error(client, login_failure):
7070

7171

7272
def test_login_bad_code(client, login_bad_code):
73-
with pytest.raises(exceptions.ApiError) as excinfo:
73+
with pytest.raises(exceptions.ApiHttpError) as excinfo:
7474
client.login('name', 'wrong')
7575
error = excinfo.value
7676
assert error.status_code == 422
77-
assert error.message == 'UNKNOWN'
77+
assert error.message == 'error http return code: 422'
7878

7979

8080
def test_keepalive_success(logged_in_client, keepalive_success):

0 commit comments

Comments
 (0)