diff --git a/src/common.hpp b/src/common.hpp index ea7ab291dd..2e2a89cd3c 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -153,7 +153,9 @@ namespace websocketpp { GENERIC = 0, // send attempted when endpoint write queue was full SEND_QUEUE_FULL = 1, - PAYLOAD_VIOLATION = 2 + PAYLOAD_VIOLATION = 2, + ENDPOINT_UNSECURE = 3, + ENDPOINT_UNAVAILABLE = 4 }; } diff --git a/src/roles/client.hpp b/src/roles/client.hpp index 4f37886996..7a123fd2de 100644 --- a/src/roles/client.hpp +++ b/src/roles/client.hpp @@ -253,18 +253,23 @@ private: template typename endpoint_traits::connection_ptr client::connect(const std::string& u) { - // TODO: will throw, should we catch and wrap? + // TODO: uri constructor will throw, should we catch and wrap? uri_ptr location(new uri(u)); if (location->get_secure() && !m_endpoint.is_secure()) { - // TODO: what kind of exception does client throw? - throw ""; + throw websocketpp::exception("Endpoint doesn't support secure connections.",websocketpp::error::ENDPOINT_UNSECURE); } tcp::resolver::query query(location->get_host(),location->get_port_str()); tcp::resolver::iterator iterator = m_resolver.resolve(query); connection_ptr con = m_endpoint.create_connection(); + + if (!con) { + throw websocketpp::exception("Endpoint is unavailable.", + websocketpp::error::ENDPOINT_UNAVAILABLE); + } + con->set_uri(location); boost::asio::async_connect(