fix: Better error detection for AVE API commands

- Added _is_error_output helper to detect errors in CLI output
- API errors like 'API error 403' now show proper error message instead of 'No price data available'
- Updated all command execution methods to use the helper
This commit is contained in:
shokollm
2026-04-13 23:55:51 +00:00
parent 2c3b6ef073
commit 6b8912a7eb

View File

@@ -472,6 +472,15 @@ class ConversationalAgent:
# Track pending command after acknowledgment
self.pending_command = None
def _is_error_output(self, code: int, output: str) -> bool:
"""Check if the command output contains an error."""
if code != 0:
return True
# Check for common error patterns in output
if output.startswith("Error:") or "API error" in output or "api key invalid" in output.lower():
return True
return False
def _handle_slash_command(self, user_message: str) -> Dict[str, Any]:
"""Handle slash command help requests.
@@ -664,7 +673,14 @@ class ConversationalAgent:
"trending",
["--chain", "bsc", "--page-size", "10"],
)
if code == 0:
if self._is_error_output(code, output):
return {
"response": f"Failed to get trending tokens: {output}",
"thinking": None,
"strategy_updated": False,
"strategy_needs_confirmation": False,
"success": True,
}
try:
data = json.loads(output)
# Handle both dict with 'tokens' key and direct list
@@ -709,14 +725,6 @@ class ConversationalAgent:
"strategy_needs_confirmation": False,
"success": True,
}
else:
return {
"response": f"Failed to get trending tokens: {output}",
"thinking": None,
"strategy_updated": False,
"strategy_needs_confirmation": False,
"success": True,
}
except Exception as e:
return {
"response": f"Error getting trending tokens: {str(e)}",
@@ -733,7 +741,14 @@ class ConversationalAgent:
"search",
["--keyword", keyword.strip(), "--chain", "bsc", "--limit", "10"],
)
if code == 0:
if self._is_error_output(code, output):
return {
"response": f"Failed to search tokens: {output}",
"thinking": None,
"strategy_updated": False,
"strategy_needs_confirmation": False,
"success": True,
}
try:
data = json.loads(output)
# Handle both dict with 'tokens' key and direct list
@@ -778,14 +793,6 @@ class ConversationalAgent:
"strategy_needs_confirmation": False,
"success": True,
}
else:
return {
"response": f"Failed to search tokens: {output}",
"thinking": None,
"strategy_updated": False,
"strategy_needs_confirmation": False,
"success": True,
}
except Exception as e:
return {
"response": f"Error searching tokens: {str(e)}",
@@ -802,7 +809,14 @@ class ConversationalAgent:
"risk",
["--address", address.strip(), "--chain", "bsc"],
)
if code == 0:
if self._is_error_output(code, output):
return {
"response": f"Failed to get risk data: {output}",
"thinking": None,
"strategy_updated": False,
"strategy_needs_confirmation": False,
"success": True,
}
try:
data = json.loads(output)
data_field = data.get("data")
@@ -862,14 +876,6 @@ class ConversationalAgent:
"strategy_needs_confirmation": False,
"success": True,
}
else:
return {
"response": f"Failed to get risk data: {output}",
"thinking": None,
"strategy_updated": False,
"strategy_needs_confirmation": False,
"success": True,
}
except Exception as e:
return {
"response": f"Error getting risk data: {str(e)}",
@@ -994,7 +1000,14 @@ class ConversationalAgent:
"price",
["--tokens"] + tokens_list,
)
if code == 0:
if self._is_error_output(code, output):
return {
"response": f"Failed to get prices: {output}",
"thinking": None,
"strategy_updated": False,
"strategy_needs_confirmation": False,
"success": True,
}
try:
data = json.loads(output)
prices = data.get("data", {})
@@ -1029,14 +1042,6 @@ class ConversationalAgent:
"strategy_needs_confirmation": False,
"success": True,
}
else:
return {
"response": f"Failed to get prices: {output}",
"thinking": None,
"strategy_updated": False,
"strategy_needs_confirmation": False,
"success": True,
}
except Exception as e:
return {
"response": f"Error getting prices: {str(e)}",