better error handling in WebSocketAPI