rough-pizza-5956
08/05/2025, 10:31 AMRoomInputOptions.close_on_disconnect=False) {"participant": "identity-CrYS", "reason": "CLIENT_INITIATED", "pid": 64112, "job how to capture this error in our code as there erros are raised by external librariestall-airline-16756
08/05/2025, 10:31 AMtall-airline-16756
08/05/2025, 10:32 AMAPIConnectionError, you can follow these steps:
1. Use Try-Except Blocks: Wrap the code that might raise an error in a try-except block to handle specific exceptions.
try:
# Code that might raise an error
except APIConnectionError as e:
print(f"Connection error: {e.message}")
except Exception as e:
print(f"Unexpected error: {str(e)}")
2. Implement Retry Logic: For transient errors, include retry logic. For example:
for i in range(self._conn_options.max_retry):
try:
# API request
except Exception as e:
if i < self._conn_options.max_retry - 1:
await asyncio.sleep(self._conn_options.retry_interval)
else:
raise APIConnectionError("Failed after all retries") from e
3. Log Errors: Use logging to capture error details for debugging.
except Exception as e:
logger.exception("Failed to call API")
raise APIConnectionError() from e
4. Inspect Error Attributes: For example, check the retryable attribute of APIConnectionError or the status_code of APIStatusError to determine the error type and handle it accordingly.
These practices will help you effectively capture and manage errors in your code.rough-pizza-5956
08/05/2025, 12:09 PMtall-airline-16756
08/05/2025, 12:09 PM@session.on_error. The AgentSession will emit an ErrorEvent whenever something goes wrong, and here’s a friendly way to handle it:
1. Error Event Emission: The AgentSession sends out an ErrorEvent for things like STT, TTS, or LLM hiccups.
2. Recoverable vs. Unrecoverable Errors:
- If event.error.recoverable is True, the session will try the operation again.
- If it’s False, that’s your cue to step in—maybe notify the user or log what happened.
3. Example Implementation:
@session.on_error
async def handle_error(event: ErrorEvent):
if event.error.recoverable:
logger.warning(f"[Recoverable Error] Source: {event.source}, Error: {event.error}")
else:
logger.error(f"[Non-Recoverable Error] Source: {event.source}, Error: {event.error}")
await session.say("Something went wrong while processing. Please try again in a moment.")
4. Custom Handling: You can also get creative—like playing a custom audio message or transferring calls when errors can’t be fixed automatically.
This way, you’re handling errors smoothly and keeping the experience as seamless as possible for your users.
Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | Events and error handling | LiveKit Docsrough-pizza-5956
08/05/2025, 12:14 PMtall-airline-16756
08/05/2025, 12:14 PM@session.on_error and handle the ErrorEvent in LiveKit, you'll want to import these:
from livekit.agents.voice import AgentSession
from livekit.agents.voice.events import ErrorEvent
These imports make it easy to create your session and smoothly handle any errors right inside your callback function. Let me know if you need a hand with anything else!