From e0d5f182a3e4159e573ffbd9bee6256b59cbd979 Mon Sep 17 00:00:00 2001 From: Benjamin Ross Date: Sun, 25 Mar 2018 17:09:55 -0700 Subject: [PATCH] Fixed issue with message -> code. added rate limit exception and tset --- gdax/exceptions.py | 9 ++++++++- gdax/public_client.py | 3 +++ tests/test_error_handling.py | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/gdax/exceptions.py b/gdax/exceptions.py index 8320f4e..ab167ad 100644 --- a/gdax/exceptions.py +++ b/gdax/exceptions.py @@ -28,7 +28,7 @@ def code(self): return self._code @message.setter - def message(self, code): + def code(self, code): self._code = code @@ -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 diff --git a/gdax/public_client.py b/gdax/public_client.py index 028d2e9..5b06a6d 100644 --- a/gdax/public_client.py +++ b/gdax/public_client.py @@ -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) diff --git a/tests/test_error_handling.py b/tests/test_error_handling.py index ccbe841..7a8fce5 100644 --- a/tests/test_error_handling.py +++ b/tests/test_error_handling.py @@ -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):