Skip to content

Commit 67612aa

Browse files
committed
Fixing up a call non standard std::exception constructor with string and other misc websocket exception constructor calls.
1 parent 09de1a3 commit 67612aa

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

Release/include/cpprest/ws_client.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,13 @@ class websocket_exception : public std::exception
176176
websocket_exception(const utility::string_t &whatArg)
177177
: m_msg(utility::conversions::to_utf8string(whatArg)) {}
178178

179+
#ifdef _MS_WINDOWS
179180
/// <summary>
180181
/// Creates an <c>websocket_exception</c> with just a string message and no error code.
181182
/// </summary>
182183
/// <param name="whatArg">Error message string.</param>
183184
websocket_exception(std::string whatArg) : m_msg(std::move(whatArg)) {}
185+
#endif
184186

185187
/// <summary>
186188
/// Creates a <c>websocket_exception</c> from a error code using the current platform error category.
@@ -203,6 +205,7 @@ class websocket_exception : public std::exception
203205
m_msg(utility::conversions::to_utf8string(whatArg))
204206
{}
205207

208+
#ifdef _MS_WINDOWS
206209
/// <summary>
207210
/// Creates a <c>websocket_exception</c> from a error code and string message.
208211
/// </summary>
@@ -212,6 +215,7 @@ class websocket_exception : public std::exception
212215
: m_errorCode(utility::details::create_error_code(errorCode)),
213216
m_msg(std::move(whatArg))
214217
{}
218+
#endif
215219

216220
/// <summary>
217221
/// Creates a <c>websocket_exception</c> from a error code and category. The message of the error code will be used

Release/src/websockets/client/ws_client.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ class ws_desktop_client : public _websocket_client_impl, public std::enable_shar
170170
m_client.close(m_con, static_cast<websocketpp::close::status::value>(status), utility::conversions::to_utf8string(reason), ec);
171171
if (ec.value() != 0)
172172
{
173-
websocket_exception wx(utility::conversions::to_string_t(ec.message()));
174-
return pplx::task_from_exception<void>(wx);
173+
return pplx::task_from_exception<void>(ec.message());
175174
}
176175
}
177176
return pplx::task<void>(m_close_tce);
@@ -195,7 +194,7 @@ class ws_desktop_client : public _websocket_client_impl, public std::enable_shar
195194
std::lock_guard<std::mutex> lock(m_receive_queue_lock);
196195
close_pending_tasks_with_error();
197196
m_state = CLOSED;
198-
m_connect_tce.set_exception(websocket_exception(_XPLATSTR("Connection attempt failed.")));
197+
m_connect_tce.set_exception(websocket_exception("Connection attempt failed."));
199198
});
200199

201200
m_client.set_message_handler([this](websocketpp::connection_hdl, message_ptr msg)
@@ -324,7 +323,7 @@ class ws_desktop_client : public _websocket_client_impl, public std::enable_shar
324323
{
325324
if (!m_connect_tce._IsTriggered())
326325
{
327-
return pplx::task_from_exception<void>(websocket_exception(_XPLATSTR("Client not connected.")));
326+
return pplx::task_from_exception<void>(websocket_exception("Client not connected."));
328327
}
329328

330329
switch (msg._m_impl->message_type())
@@ -333,18 +332,18 @@ class ws_desktop_client : public _websocket_client_impl, public std::enable_shar
333332
case websocket_message_type::binary_message:
334333
break;
335334
default:
336-
return pplx::task_from_exception<void>(websocket_exception(_XPLATSTR("Invalid message type")));
335+
return pplx::task_from_exception<void>(websocket_exception("Invalid message type"));
337336
}
338337

339338
const auto length = msg._m_impl->length();
340339
if (length == 0)
341340
{
342-
return pplx::task_from_exception<void>(websocket_exception(_XPLATSTR("Cannot send empty message.")));
341+
return pplx::task_from_exception<void>(websocket_exception("Cannot send empty message."));
343342
}
344343

345344
if (length > UINT_MAX)
346345
{
347-
return pplx::task_from_exception<void>(websocket_exception(_XPLATSTR("Message size too large. Ensure message length is less than or equal to UINT_MAX.")));
346+
return pplx::task_from_exception<void>(websocket_exception("Message size too large. Ensure message length is less than or equal to UINT_MAX."));
348347
}
349348

350349
{
@@ -370,7 +369,7 @@ class ws_desktop_client : public _websocket_client_impl, public std::enable_shar
370369
if (m_state > CONNECTED)
371370
{
372371
// The client has already been closed.
373-
return pplx::task_from_exception<websocket_incoming_message>(std::make_exception_ptr(websocket_exception(_XPLATSTR("Websocket connection has closed."))));
372+
return pplx::task_from_exception<websocket_incoming_message>(std::make_exception_ptr(websocket_exception("Websocket connection has closed.")));
374373
}
375374

376375
if (m_receive_msg_queue.empty())
@@ -421,7 +420,7 @@ class ws_desktop_client : public _websocket_client_impl, public std::enable_shar
421420
{
422421
if (bytes_read != length)
423422
{
424-
throw websocket_exception(_XPLATSTR("Failed to read required length of data from the stream."));
423+
throw websocket_exception("Failed to read required length of data from the stream.");
425424
}
426425
});
427426
}
@@ -509,7 +508,7 @@ class ws_desktop_client : public _websocket_client_impl, public std::enable_shar
509508
// There are tasks waiting to receive a message, signal them
510509
auto tce = m_receive_task_queue.front();
511510
m_receive_task_queue.pop();
512-
tce.set_exception(std::make_exception_ptr(websocket_exception(_XPLATSTR("Websocket connection has been closed."))));
511+
tce.set_exception(std::make_exception_ptr(websocket_exception("Websocket connection has been closed.")));
513512
}
514513
}
515514

Release/src/websockets/client/ws_msg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pplx::task<std::string> websocket_incoming_message::extract_string() const
104104
{
105105
if (_m_impl->message_type() == websocket_message_type::binary_message)
106106
{
107-
return pplx::task_from_exception<std::string>(websocket_exception(_XPLATSTR("Invalid message type")));
107+
return pplx::task_from_exception<std::string>(websocket_exception("Invalid message type"));
108108
}
109109

110110
auto m_impl = _m_impl;
@@ -114,4 +114,4 @@ pplx::task<std::string> websocket_incoming_message::extract_string() const
114114

115115
}}}}
116116
#endif // _NOT_PHONE8_
117-
#endif
117+
#endif

Release/tests/Functional/websockets/utilities/test_websocket_server.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ namespace utilities {
8787

8888
const std::string& username() override
8989
{
90-
throw std::exception("NYI");
90+
throw std::runtime_error("NYI");
9191
}
9292
const std::string& password() override
9393
{
94-
throw std::exception("NYI");
94+
throw std::runtime_error("NYI");
9595
}
9696

9797
const std::string& get_header_val(const std::string& header_name) override

0 commit comments

Comments
 (0)