From 57dbc19f8d2e558bafa6a0aabf7b39e3d005e0bb Mon Sep 17 00:00:00 2001 From: Morty Space Date: Wed, 18 May 2022 20:01:27 +0200 Subject: [PATCH] fix: added retries for connection error --- .vscode/settings.json | 2 +- docs/source/conf.py | 2 +- src/cryptocom/exchange/api.py | 16 ++++++---------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index b9d0e79..39a3cb4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,5 +26,5 @@ }, "files.insertFinalNewline": true, "git.ignoreLimitWarning": true, - "restructuredtext.confPath": "${workspaceFolder}/docs/source", + "esbonio.sphinx.confDir": "${workspaceFolder}/docs/source", } diff --git a/docs/source/conf.py b/docs/source/conf.py index 929e512..496fdd1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -83,7 +83,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -# html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the diff --git a/src/cryptocom/exchange/api.py b/src/cryptocom/exchange/api.py index 771d636..edb0a06 100644 --- a/src/cryptocom/exchange/api.py +++ b/src/cryptocom/exchange/api.py @@ -220,22 +220,18 @@ async def request(self, method, path, params=None, data=None, sign=False): f"Error: {resp_json}. " f"Status: {resp.status_code}. Json params: {data}" ) - except httpx.ConnectError: - raise ApiError(f"Cannot connect to host {self.root_url}") - except (asyncio.TimeoutError, httpx.ReadError) as exc: + except ( + asyncio.TimeoutError, + httpx.ReadError, + httpx.ConnectError, + json.JSONDecodeError, + ) as exc: if count == self.retries: raise ApiError( f"Timeout or read error, retries: {self.retries}. " f"Path: {path}. Data: {data}. Exc: {exc}" ) from exc continue - except json.JSONDecodeError: - if resp.status_code == 429: - continue - raise ApiError( - f"Can't decode json, content: {resp.text}. " - f"Code: {resp.status_code}" - ) finally: await client.aclose()