Skip to content

Commit

Permalink
Fixed issue with message -> code. added rate limit exception and tset
Browse files Browse the repository at this point in the history
  • Loading branch information
bpross committed Mar 26, 2018
1 parent 85e93c0 commit e0d5f18
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gdax/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def code(self):
return self._code

@message.setter
def message(self, code):
def code(self, code):
self._code = code


Expand Down Expand Up @@ -60,6 +60,13 @@ class NotFoundGdaxRequest(GdaxException):
pass


class GdaxRateLimitRequest(GdaxException):
"""
Raised on 429 response from GDAX
"""
pass


class UnknownGdaxClientRequest(GdaxException):
"""
Raised on 4XX responses not tracked
Expand Down
3 changes: 3 additions & 0 deletions gdax/public_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def _determine_response(self, response):
elif response.status_code == HTTPStatus.NOT_FOUND:
raise exceptions.NotFoundGdaxRequest(message,
HTTPStatus.NOT_FOUND)
elif response.status_code == HTTPStatus.TOO_MANY_REQUESTS:
raise exceptions.GdaxRateLimitRequest(message,
HTTPStatus.TOO_MANY_REQUESTS)
else: # Other 4XX response not yet mapped
raise exceptions.UnknownGdaxClientRequest(message,
response.status_code)
Expand Down
1 change: 1 addition & 0 deletions tests/test_error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def client():
(403, gdax.exceptions.ForbiddenGdaxRequest),
(404, gdax.exceptions.NotFoundGdaxRequest),
(422, gdax.exceptions.UnknownGdaxClientRequest),
(429, gdax.exceptions.GdaxRateLimitRequest),
(500, gdax.exceptions.InternalErrorGdaxRequest)])
@patch('requests.get')
def test_gdax_exceptions(mock_request, client, code, exception):
Expand Down

0 comments on commit e0d5f18

Please sign in to comment.