-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for fallback nodes (#45)
* Add support for fallback nodes * Review fixes * Review fixes * Use repr for error logging
- Loading branch information
Showing
7 changed files
with
151 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "sw-utils" | ||
version = "0.3.10" | ||
version = "0.3.11" | ||
description = "StakeWise Python utils" | ||
authors = ["StakeWise Labs <[email protected]>"] | ||
license = "GPL-3.0-or-later" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import asyncio | ||
import logging | ||
|
||
import aiohttp | ||
import requests | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class RecoverableServerError(Exception): | ||
""" | ||
Wrapper around ClientResponseError for HTTP 500 errors. | ||
Only for internal use inside sw-utils library. | ||
Do not raise `RecoverableServerError` in application code. | ||
""" | ||
|
||
def __init__(self, origin: requests.HTTPError | aiohttp.ClientResponseError): | ||
self.origin = origin | ||
if isinstance(origin, requests.HTTPError): | ||
self.status_code = origin.response.status_code | ||
self.uri = origin.response.url | ||
elif isinstance(origin, aiohttp.ClientResponseError): | ||
self.status_code = origin.status | ||
self.uri = origin.request_info | ||
|
||
super().__init__() | ||
|
||
def __str__(self): | ||
return ( | ||
f'RecoverableServerError (status_code: {self.status_code}, ' | ||
f'uri: {self.uri}): {self.origin}' | ||
) | ||
|
||
|
||
AiohttpRecoveredErrors = ( | ||
aiohttp.ClientConnectionError, | ||
RecoverableServerError, | ||
asyncio.TimeoutError, | ||
) | ||
RequestsRecoveredErrors = ( | ||
requests.ConnectionError, | ||
requests.Timeout, | ||
RecoverableServerError, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters