Skip to content

Commit 2ccfb90

Browse files
committed
refactor: improve error handling in AgentHumanAPI
- Enhanced exception handling in the AgentHumanAPI class to separately manage APIStatusError and AgentHumanException. - Added logging for non-retryable APIStatusError to provide better insights during failures. - Adjusted retry logic to ensure proper handling of exceptions and maintain clarity in error reporting.
1 parent 1cf3a30 commit 2ccfb90

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

  • livekit-plugins/livekit-plugins-agenthuman/livekit/plugins/agenthuman

livekit-plugins/livekit-plugins-agenthuman/livekit/plugins/agenthuman/api.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,15 @@ async def create_session(
117117
raise AgentHumanException(
118118
f"Unexpected API response structure: {session_data}"
119119
) from e
120-
except (APIStatusError, AgentHumanException):
120+
except AgentHumanException:
121121
raise
122+
except APIStatusError as e:
123+
last_exc = e
124+
if not e.retryable:
125+
raise
126+
logger.warning(
127+
"[agenthuman] failed to call agenthuman api", extra={"error": str(e)}
128+
)
122129
except Exception as e:
123130
last_exc = e
124131
if isinstance(e, APIConnectionError):
@@ -128,9 +135,11 @@ async def create_session(
128135
else:
129136
logger.exception("[agenthuman] failed to call agenthuman api")
130137

131-
if i < self._conn_options.max_retry - 1:
132-
await asyncio.sleep(self._conn_options.retry_interval)
138+
if i < self._conn_options.max_retry - 1:
139+
await asyncio.sleep(self._conn_options.retry_interval)
133140

141+
if isinstance(last_exc, APIStatusError):
142+
raise last_exc
134143
raise APIConnectionError(
135144
"Failed to create AgentHuman session after all retries"
136145
) from last_exc

0 commit comments

Comments
 (0)