Improved error handling for crypto commands (#2704)

* Improved error handling

* Updated tests
This commit is contained in:
Colin Delahunty
2022-10-04 16:07:45 +02:00
committed by GitHub
parent c268d85128
commit e3051bb176
8 changed files with 19 additions and 14 deletions

View File

@@ -40,13 +40,15 @@ DEX_COLUMNS = [
@log_start_end(log=logger)
def _make_request(url: str) -> Optional[dict]:
def _make_request(url: str, verbose: bool = True) -> Optional[dict]:
"""Helper method handles dappradar api requests. [Source: https://dappradar.com/]
Parameters
----------
url: str
endpoint url
verbose: bool
whether to print the text from the response
Returns
-------
dict:
@@ -60,13 +62,15 @@ def _make_request(url: str) -> Optional[dict]:
}
response = requests.get(url, headers=headers)
if not 200 <= response.status_code < 300:
console.print(f"[red]dappradar api exception: {response.text}[/red]")
if verbose:
console.print(f"[red]dappradar api exception: {response.text}[/red]")
return None
try:
return response.json()
except Exception as e: # noqa: F841
logger.exception("Invalid Response: %s", str(e))
console.print(f"[red]Invalid Response:: {response.text}[/red]")
if verbose:
console.print(f"[red]Invalid Response:: {response.text}[/red]")
return None
@@ -217,7 +221,8 @@ def get_top_dapps(sortby: str = "", limit: int = 10) -> pd.DataFrame:
data = _make_request(
"https://dappradar.com/v2/api/dapps?params=WkdGd2NISmhaR0Z5Y0dGblpUMHhKbk5uY205MWNEMX"
"RZWGdtWTNWeWNtVnVZM2s5VlZORUptWmxZWFIxY21Wa1BURW1jbUZ1WjJVOVpHRjVKbk52Y25ROWRYTmxjaVp"
"2Y21SbGNqMWtaWE5qSm14cGJXbDBQVEky"
"2Y21SbGNqMWtaWE5qSm14cGJXbDBQVEky",
False,
)
if data:
arr = [

View File

@@ -32,7 +32,7 @@ def display_top_nfts(limit: int = 10, sortby: str = "", export: str = "") -> Non
df = dappradar_model.get_top_nfts(sortby, limit)
if df.empty:
console.print("Failed to fetch data from DappRadar\n")
console.print("[red]Failed to fetch data from DappRadar[/red]\n")
return
for col in ["Floor Price [$]", "Avg Price [$]", "Market Cap [$]", "Volume [$]"]:
if col in df.columns:
@@ -73,7 +73,7 @@ def display_top_games(limit: int = 10, export: str = "", sortby: str = "") -> No
df = dappradar_model.get_top_games(sortby, limit)
if df.empty:
console.print("Failed to fetch data from DappRadar\n")
console.print("[red]Failed to fetch data from DappRadar[/red]\n")
return
for col in ["Daily Users", "Daily Volume [$]"]:
if col in df.columns:
@@ -109,7 +109,7 @@ def display_top_dexes(limit: int = 10, export: str = "", sortby: str = "") -> No
df = dappradar_model.get_top_dexes(sortby, limit)
if df.empty:
console.print("Failed to fetch data from DappRadar\n")
console.print("[red]Failed to fetch data from DappRadar[/red]\n")
return
for col in ["Daily Users", "Daily Volume [$]"]:
if col in df.columns:
@@ -145,7 +145,7 @@ def display_top_dapps(limit: int = 10, export: str = "", sortby: str = "") -> No
df = dappradar_model.get_top_dapps(sortby, limit)
if df.empty:
console.print("Failed to fetch data from DappRadar\n")
console.print("[red]Failed to fetch data from DappRadar[/red]\n")
return
for col in ["Daily Users", "Daily Volume [$]"]:
if col in df.columns:

View File

@@ -1,2 +1,2 @@
Failed to fetch data from DappRadar
[red]Failed to fetch data from DappRadar[/red]

View File

@@ -1,2 +1,2 @@
Failed to fetch data from DappRadar
[red]Failed to fetch data from DappRadar[/red]

View File

@@ -1,2 +1,2 @@
Failed to fetch data from DappRadar
[red]Failed to fetch data from DappRadar[/red]

View File

@@ -1,2 +1,2 @@
Failed to fetch data from DappRadar
[red]Failed to fetch data from DappRadar[/red]

View File

@@ -1,2 +1,2 @@
Failed to fetch data from DappRadar
[red]Failed to fetch data from DappRadar[/red]

View File

@@ -1,2 +1,2 @@
Failed to fetch data from DappRadar
[red]Failed to fetch data from DappRadar[/red]