Skip to content
Snippets Groups Projects
Commit 2a5f786f authored by Seva's avatar Seva Committed by Adrien Béraud
Browse files

http: handle request error codes through terminate

parent c690d060
No related branches found
No related tags found
No related merge requests found
...@@ -707,8 +707,10 @@ Request::connect(std::vector<asio::ip::tcp::endpoint>&& endpoints, HandlerCb cb) ...@@ -707,8 +707,10 @@ Request::connect(std::vector<asio::ip::tcp::endpoint>&& endpoints, HandlerCb cb)
// try to connect to any until one works // try to connect to any until one works
conn_->async_connect(std::move(endpoints), [this, cb] conn_->async_connect(std::move(endpoints), [this, cb]
(const asio::error_code& ec, const asio::ip::tcp::endpoint& endpoint){ (const asio::error_code& ec, const asio::ip::tcp::endpoint& endpoint){
if (ec == asio::error::operation_aborted) if (ec == asio::error::operation_aborted){
terminate(ec);
return; return;
}
else if (ec and logger_) else if (ec and logger_)
logger_->e("[http:client] [request:%i] connect: failed with all endpoints", id_); logger_->e("[http:client] [request:%i] connect: failed with all endpoints", id_);
else { else {
...@@ -757,9 +759,7 @@ Request::send() ...@@ -757,9 +759,7 @@ Request::send()
} }
else if (!conn_ or !conn_->is_open()){ else if (!conn_ or !conn_->is_open()){
connect(std::move(endpoints), [this](const asio::error_code &ec){ connect(std::move(endpoints), [this](const asio::error_code &ec){
if (ec == asio::error::operation_aborted) if (ec)
return;
else if (ec)
terminate(asio::error::not_connected); terminate(asio::error::not_connected);
else else
post(); post();
...@@ -822,9 +822,7 @@ Request::terminate(const asio::error_code& ec) ...@@ -822,9 +822,7 @@ Request::terminate(const asio::error_code& ec)
void void
Request::handle_request(const asio::error_code& ec) Request::handle_request(const asio::error_code& ec)
{ {
if (ec == asio::error::operation_aborted) if (ec and ec != asio::error::eof){
return;
else if (ec and ec != asio::error::eof){
terminate(ec); terminate(ec);
return; return;
} }
...@@ -843,13 +841,7 @@ Request::handle_request(const asio::error_code& ec) ...@@ -843,13 +841,7 @@ Request::handle_request(const asio::error_code& ec)
void void
Request::handle_response_header(const asio::error_code& ec) Request::handle_response_header(const asio::error_code& ec)
{ {
if (ec == asio::error::operation_aborted) if (ec && ec != asio::error::eof){
return;
else if ((ec == asio::error::eof) or (ec == asio::error::connection_reset)){
terminate(ec);
return;
}
else if ((ec == asio::error::eof) || (ec == asio::error::connection_reset)){
terminate(ec); terminate(ec);
return; return;
} }
...@@ -901,15 +893,7 @@ Request::handle_response_header(const asio::error_code& ec) ...@@ -901,15 +893,7 @@ Request::handle_response_header(const asio::error_code& ec)
void void
Request::handle_response_body(const asio::error_code& ec, const size_t bytes) Request::handle_response_body(const asio::error_code& ec, const size_t bytes)
{ {
if (ec == asio::error::operation_aborted){ if (ec && ec != asio::error::eof){
terminate(ec);
return;
}
else if ((ec == asio::error::eof) or (ec == asio::error::connection_reset)){
terminate(ec);
return;
}
else if (ec && ec != asio::error::eof){
terminate(ec); terminate(ec);
return; return;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment