refactor: improve epic web send_command implementation.

This commit is contained in:
b-rowan
2024-01-27 09:42:35 -07:00
parent a2c2aa2377
commit c443170f78

View File

@@ -44,7 +44,6 @@ class ePICWebAPI(BaseWebAPI):
post = privileged or not parameters == {}
async with httpx.AsyncClient(transport=settings.transport()) as client:
for i in range(settings.get("get_data_retries", 1) + 1):
try:
if post:
response = await client.post(
@@ -61,17 +60,15 @@ class ePICWebAPI(BaseWebAPI):
timeout=5,
)
if not response.status_code == 200:
continue
if not ignore_errors:
raise APIError(
f"Web command {command} failed with status code {response.status_code}"
)
return {}
json_data = response.json()
if json_data:
# The API can return a fail status if the miner cannot return the requested data. Catch this and pass
if (
"result" in json_data
and json_data["result"] is False
and not post
):
if not i > settings.get("get_data_retries", 1):
continue
if not json_data.get("result", True) and not post:
if not ignore_errors:
raise APIError(json_data["error"])
return json_data