@@ -631,7 +631,15 @@ class asio_context final : public request_context, public std::enable_shared_fro
631
631
m_context->m_timer .reset ();
632
632
// // Replace the connection. This causes old connection object to go out of scope.
633
633
auto client = std::static_pointer_cast<asio_client>(m_context->m_http_client );
634
- m_context->m_connection = client->obtain_connection (m_context->m_request );
634
+ try
635
+ {
636
+ m_context->m_connection = client->obtain_connection (m_context->m_request );
637
+ }
638
+ catch (...)
639
+ {
640
+ m_context->report_exception (std::current_exception ());
641
+ return ;
642
+ }
635
643
636
644
auto endpoint = *endpoints;
637
645
m_context->m_connection ->async_connect (endpoint,
@@ -688,7 +696,15 @@ class asio_context final : public request_context, public std::enable_shared_fro
688
696
return ;
689
697
}
690
698
691
- m_context->upgrade_to_ssl ();
699
+ try
700
+ {
701
+ m_context->upgrade_to_ssl ();
702
+ }
703
+ catch (...)
704
+ {
705
+ m_context->report_exception (std::current_exception ());
706
+ return ;
707
+ }
692
708
693
709
m_ssl_tunnel_established (m_context);
694
710
}
@@ -1009,7 +1025,15 @@ class asio_context final : public request_context, public std::enable_shared_fro
1009
1025
{
1010
1026
// Replace the connection. This causes old connection object to go out of scope.
1011
1027
auto client = std::static_pointer_cast<asio_client>(m_http_client);
1012
- m_connection = client->obtain_connection (m_request);
1028
+ try
1029
+ {
1030
+ m_connection = client->obtain_connection (m_request);
1031
+ }
1032
+ catch (...)
1033
+ {
1034
+ request_context::report_exception (std::current_exception ());
1035
+ return ;
1036
+ }
1013
1037
1014
1038
auto endpoint = *endpoints;
1015
1039
m_connection->async_connect (
@@ -1330,7 +1354,16 @@ class asio_context final : public request_context, public std::enable_shared_fro
1330
1354
// Create a new context and copy the request object, completion event and
1331
1355
// cancellation registration to maintain the old state.
1332
1356
// This also obtains a new connection from pool.
1333
- auto new_ctx = create_request_context (m_http_client, m_request);
1357
+ std::shared_ptr<request_context> new_ctx;
1358
+ try
1359
+ {
1360
+ new_ctx = create_request_context (m_http_client, m_request);
1361
+ }
1362
+ catch (...)
1363
+ {
1364
+ report_exception (std::current_exception ());
1365
+ return ;
1366
+ }
1334
1367
1335
1368
// If the request contains a valid instream, we try to rewind it to
1336
1369
// replay the just-failed request. Otherwise we assume that no data
@@ -1940,7 +1973,15 @@ void asio_client::send_request(const std::shared_ptr<request_context>& request_c
1940
1973
pplx::task<http_response> asio_client::propagate (http_request request)
1941
1974
{
1942
1975
auto self = std::static_pointer_cast<_http_client_communicator>(shared_from_this ());
1943
- auto context = details::asio_context::create_request_context (self, request);
1976
+ std::shared_ptr<request_context> context;
1977
+ try
1978
+ {
1979
+ context = details::asio_context::create_request_context (self, request);
1980
+ }
1981
+ catch (...)
1982
+ {
1983
+ return pplx::task_from_exception<http_response>(std::current_exception ());
1984
+ }
1944
1985
1945
1986
// Use a task to externally signal the final result and completion of the task.
1946
1987
auto result_task = pplx::create_task (context->m_request_completion );
0 commit comments