Skip to content

Commit

Permalink
fix: added retries for connection error
Browse files Browse the repository at this point in the history
  • Loading branch information
yarikdevcom committed May 18, 2022
1 parent 9f369ec commit 57dbc19
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
},
"files.insertFinalNewline": true,
"git.ignoreLimitWarning": true,
"restructuredtext.confPath": "${workspaceFolder}/docs/source",
"esbonio.sphinx.confDir": "${workspaceFolder}/docs/source",
}
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 6 additions & 10 deletions src/cryptocom/exchange/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 57dbc19

Please sign in to comment.