I have a question about error handling when on_fail() is called. Currently, I have code that basically follow your example. The question is highlighted below.
I do see this kind of messages in the log when errors happen, but can’t figure out a way to get the error myself.
Thanks for your help. I appreciate it.
// .h
class WebSocketWrapper {
public:
// ...
/** Some short names for websocketpp types */
typedef websocketpp::client<websocketpp::config::asio_tls_client> WebSocketPPClient;
typedef websocketpp::config::asio_tls_client::message_type::ptr WebSocketPPMessagePtr;
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> WebSocketPPContextPtr;
typedef websocketpp::lib::lock_guard<websocketpp::lib::mutex> WebSocketPPScopedLock;
typedef websocketpp::connection_hdl WebSocketPPConnectionHandler;
typedef websocketpp::lib::error_code WebSocketPPErrorCode;
private:
// ...
}
// .cpp
void WebSocketWrapper::init() {
// Set up access channels to log everything.
mpWebSocketClient->set_access_channels(websocketpp::log::alevel::all);
// Initialize the Asio transport policy.
mpWebSocketClient->init_asio();
// Bind the handlers we are using.
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;
mpWebSocketClient->set_tls_init_handler(bind(&WebSocketWrapper::on_tls_init,this,::_1));
mpWebSocketClient->set_message_handler(bind(&WebSocketWrapper::on_message,this,::_1,::_2));
mpWebSocketClient->set_open_handler(bind(&WebSocketWrapper::on_open,this,::_1));
mpWebSocketClient->set_close_handler(bind(&WebSocketWrapper::on_close,this,::_1));
mpWebSocketClient->set_fail_handler(bind(&WebSocketWrapper::on_fail,this,::_1));
}
void WebSocketWrapper::on_fail(WebSocketPPConnectionHandler connectionHandler) {
// How can I get more information about the failure here?
// E.g the cause of failure, the error code, etc.
}