Error Handling
The SDK provides a hierarchy of custom exceptions for robust error handling. Catch WSSError to handle any SDK-raised error, or catch specific subclasses when you need call- or buffer-level recovery.
Exception Hierarchy
Exception Details
Example
Handling CALL_UNANSWERED for connect()
When you call connect(), the callee may not answer within the ring window. In that case the SDK raises WSSCallCommandError with error_code == "CALL_UNANSWERED" and the call remains active, so you can retry, try a different branch in your flow, or end the call.
Best Practices
- Catch specific exceptions first - Put
WSSCallClosedErroror buffer exceptions beforeWSSError - Handle buffer pressure in the audio loop - Recover from
BufferFullErrorwhere you are callingsend_audio() - Expect race conditions near call shutdown -
BufferClosedErrorandWSSCallClosedErrorcan happen when a caller hangs up mid-response - Use
error_codefor command-specific recovery -CALL_UNANSWEREDis the clearest example forconnect()flows - Choose the right shutdown method - Use
close()carefully because its behavior depends on call state: afterconnect()the agent leaves, but afteranswer()withoutconnect()the caller is disconnected too. Usedisconnect()when you explicitly want the whole call to end
Next Steps
- API Reference - Full method reference
- Advanced Topics - Logging, concurrency, and operational notes
- Call States - Valid states for each command
