Skip to content

Commit 07e3eed

Browse files
Better error logging and handling
1 parent ec59ed5 commit 07e3eed

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

plugins/acp/acp_plugin_gamesdk/acp_client.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from acp_plugin_gamesdk.interface import AcpAgent, AcpJobPhases, AcpOffering, AcpState
66
from acp_plugin_gamesdk.acp_token import AcpToken, MemoType
77
import time
8+
import traceback
89

910

1011
class AcpClient:
@@ -40,7 +41,12 @@ def browse_agents(self, cluster: Optional[str] = None, query: Optional[str] = No
4041
response = requests.get(url)
4142

4243
if response.status_code != 200:
43-
raise Exception(f"Failed to browse agents: {response.text}")
44+
raise Exception(
45+
f"Error occured in browse_agents function. Failed to browse agents.\n"
46+
f"Response status code: {response.status_code}\n"
47+
f"Response description: {response.text}\n"
48+
)
49+
4450

4551
response_json = response.json()
4652

@@ -98,7 +104,8 @@ def create_job(self, provider_address: str, price: float, job_description: str,
98104
break
99105

100106
except Exception as e:
101-
print(f"Error creating job: {e}")
107+
print(f"Error in create_job function: {e}")
108+
print(traceback.format_exc())
102109
if attempt < retry_count - 1:
103110
time.sleep(retry_delay)
104111
else:
@@ -194,7 +201,11 @@ def add_tweet(self, job_id: int, tweet_id: str, content: str):
194201
)
195202

196203
if response.status_code != 200 and response.status_code != 201:
197-
raise Exception(f"Failed to add tweet: {response.status_code} {response.text}")
204+
raise Exception(
205+
f"Error occured in add_tweet function. Failed to add tweet.\n"
206+
f"Response status code: {response.status_code}\n"
207+
f"Response description: {response.text}\n"
208+
)
198209

199210

200211
return response.json()
@@ -206,4 +217,9 @@ def reset_state(self) -> None:
206217
)
207218

208219
if response.status_code not in [200, 204]:
220+
raise Exception(
221+
f"Error occured in reset_state function. Failed to reset state\n"
222+
f"Response status code: {response.status_code}\n"
223+
f"Response description: {response.text}\n"
224+
)
209225
raise Exception(f"Failed to reset state: {response.status_code} {response.text}")

0 commit comments

Comments
 (0)