diff options
author | Jack Lloyd <[email protected]> | 2015-12-11 09:42:06 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2015-12-11 09:42:06 -0500 |
commit | 6b9a3a534071ef84c121c406559f8fc7ad546104 (patch) | |
tree | c11480ad1f07e443ba4e992fefcd618b532c2e93 /src/lib/utils/http_util/http_util.cpp | |
parent | 79a51627ee11f4d7f55d589751b30463d1f02a76 (diff) |
Reroot the exception hierarchy into a toplevel Exception class
As the alternatives are unfortunate for applications trying to catch
all library errors, and it seems deriving from std::runtime_error
causes problems with MSVC DLLs (GH #340)
Effectively reverts 2837e915d82e43
Diffstat (limited to 'src/lib/utils/http_util/http_util.cpp')
-rw-r--r-- | src/lib/utils/http_util/http_util.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/lib/utils/http_util/http_util.cpp b/src/lib/utils/http_util/http_util.cpp index 1a15d6418..c437d0148 100644 --- a/src/lib/utils/http_util/http_util.cpp +++ b/src/lib/utils/http_util/http_util.cpp @@ -30,7 +30,7 @@ std::string http_transact_asio(const std::string& hostname, tcp.connect(hostname, "http"); if(!tcp) - throw std::runtime_error("HTTP connection to " + hostname + " failed"); + throw Exception("HTTP connection to " + hostname + " failed"); tcp << message; tcp.flush(); @@ -45,7 +45,7 @@ std::string http_transact_asio(const std::string& hostname, std::string http_transact_fail(const std::string& hostname, const std::string&) { - throw std::runtime_error("Cannot connect to " + hostname + + throw Exception("Cannot connect to " + hostname + ": network code disabled in build"); } @@ -89,7 +89,7 @@ Response http_sync(http_exch_fn http_transact, { const auto protocol_host_sep = url.find("://"); if(protocol_host_sep == std::string::npos) - throw std::runtime_error("Invalid URL " + url); + throw Exception("Invalid URL " + url); const std::string protocol = url.substr(0, protocol_host_sep); const auto host_loc_sep = url.find('/', protocol_host_sep + 3); @@ -130,7 +130,7 @@ Response http_sync(http_exch_fn http_transact, std::string line1; std::getline(io, line1); if(!io || line1.empty()) - throw std::runtime_error("No response"); + throw Exception("No response"); std::stringstream response_stream(line1); std::string http_version; @@ -142,7 +142,7 @@ Response http_sync(http_exch_fn http_transact, std::getline(response_stream, status_message); if(!response_stream || http_version.substr(0,5) != "HTTP/") - throw std::runtime_error("Not an HTTP response"); + throw Exception("Not an HTTP response"); std::map<std::string, std::string> headers; std::string header_line; @@ -150,7 +150,7 @@ Response http_sync(http_exch_fn http_transact, { auto sep = header_line.find(": "); if(sep == std::string::npos || sep > header_line.size() - 2) - throw std::runtime_error("Invalid HTTP header " + header_line); + throw Exception("Invalid HTTP header " + header_line); const std::string key = header_line.substr(0, sep); if(sep + 2 < header_line.size() - 1) @@ -163,7 +163,7 @@ Response http_sync(http_exch_fn http_transact, if(status_code == 301 && headers.count("Location")) { if(allowable_redirects == 0) - throw std::runtime_error("HTTP redirection count exceeded"); + throw Exception("HTTP redirection count exceeded"); return GET_sync(headers["Location"], allowable_redirects - 1); } @@ -180,7 +180,7 @@ Response http_sync(http_exch_fn http_transact, if(header_size != "") { if(resp_body.size() != to_u32bit(header_size)) - throw std::runtime_error("Content-Length disagreement, header says " + + throw Exception("Content-Length disagreement, header says " + header_size + " got " + std::to_string(resp_body.size())); } |