|
6 | 6 | from vrcpy.errors import * |
7 | 7 |
|
8 | 8 |
|
| 9 | +call_retries = 1 |
| 10 | + |
| 11 | + |
9 | 12 | def raise_for_status(resp): |
10 | 13 | if type(resp["data"]) == bytes: |
11 | 14 | resp["data"] = json.loads(resp["data"].decode()) |
@@ -80,7 +83,19 @@ async def closeSession(self): |
80 | 83 | await self.session.close() |
81 | 84 | self.session = None |
82 | 85 |
|
83 | | - async def call(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True): |
| 86 | + async def call(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True, retries=None): |
| 87 | + for tri in range(0, (retries or call_retries) + 1): |
| 88 | + try: |
| 89 | + resp = await self._call_wrap(path, method, headers, params, json, no_auth, verify) |
| 90 | + break |
| 91 | + except requests.exceptions.ConnectionError as e: # Gosh darnit VRC team, why've you done this! |
| 92 | + if tri == (retries or call_retries): |
| 93 | + raise requests.exceptions.ConnectionError( |
| 94 | + str(e) + " ({} retries)".format(retries)) |
| 95 | + |
| 96 | + return resp |
| 97 | + |
| 98 | + async def _call_wrap(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True): |
84 | 99 | if no_auth: |
85 | 100 | return await self._call(path, method, headers, params, json, verify) |
86 | 101 |
|
@@ -188,7 +203,19 @@ def new_session(self): |
188 | 203 | self.session = requests.Session() |
189 | 204 | self.b64_auth = None |
190 | 205 |
|
191 | | - def call(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True): |
| 206 | + def call(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True, retries=None): |
| 207 | + for tri in range(0, (retries or call_retries) + 1): |
| 208 | + try: |
| 209 | + resp = self._call_wrap(path, method, headers, params, json, no_auth, verify) |
| 210 | + break |
| 211 | + except requests.exceptions.ConnectionError as e: # Gosh darnit VRC team, why've you done this! |
| 212 | + if tri == (retries or call_retries): |
| 213 | + raise requests.exceptions.ConnectionError( |
| 214 | + str(e) + " ({} retries)".format(retries)) |
| 215 | + |
| 216 | + return resp |
| 217 | + |
| 218 | + def _call_wrap(self, path, method="GET", headers={}, params={}, json={}, no_auth=False, verify=True): |
192 | 219 | headers["user-agent"] = "" |
193 | 220 |
|
194 | 221 | if no_auth: |
|
0 commit comments