fix: added retries for connection error

api-breakage
Morty Space 4 years ago
parent 9f369ec1a7
commit 57dbc19f8d
  1. 2
      .vscode/settings.json
  2. 2
      docs/source/conf.py
  3. 16
      src/cryptocom/exchange/api.py

@ -26,5 +26,5 @@
},
"files.insertFinalNewline": true,
"git.ignoreLimitWarning": true,
"restructuredtext.confPath": "${workspaceFolder}/docs/source",
"esbonio.sphinx.confDir": "${workspaceFolder}/docs/source",
}

@ -83,7 +83,7 @@ pygments_style = None
# 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

@ -220,22 +220,18 @@ class ApiProvider:
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()

Loading…
Cancel
Save