diff --git a/locator/azure_snitch.cc b/locator/azure_snitch.cc index 74f93aa3be..b6e74903db 100644 --- a/locator/azure_snitch.cc +++ b/locator/azure_snitch.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -83,6 +84,10 @@ future azure_snitch::azure_api_call(sstring path) { // Read HTTP response header first auto rsp = parser.get_parsed_response(); + if (rsp->_status_code != static_cast(http::reply::status_type::ok)) { + throw std::runtime_error(format("Error: HTTP response status {}", rsp->_status_code)); + } + auto it = rsp->_headers.find("Content-Length"); if (it == rsp->_headers.end()) { throw std::runtime_error("Error: HTTP response does not contain: Content-Length\n"); diff --git a/locator/ec2_snitch.cc b/locator/ec2_snitch.cc index f6234528be..22705aa98b 100644 --- a/locator/ec2_snitch.cc +++ b/locator/ec2_snitch.cc @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -126,6 +127,9 @@ future ec2_snitch::aws_api_call_once(sstring addr, uint16_t port, sstri if (rc == 403) { return make_exception_future(std::runtime_error("Error: Unauthorized response received when trying to communicate with instance metadata service.")); } + if (_rsp->_status_code != static_cast(http::reply::status_type::ok)) { + return make_exception_future(std::runtime_error(format("Error: HTTP response status {}", _rsp->_status_code))); + } auto it = _rsp->_headers.find("Content-Length"); if (it == _rsp->_headers.end()) { diff --git a/locator/gce_snitch.cc b/locator/gce_snitch.cc index f96e5b0640..6f638fa0de 100644 --- a/locator/gce_snitch.cc +++ b/locator/gce_snitch.cc @@ -11,6 +11,7 @@ #include #include #include "locator/gce_snitch.hh" +#include #include #include @@ -99,6 +100,10 @@ future gce_snitch::gce_api_call(sstring addr, sstring cmd) { // Read HTTP response header first auto rsp = parser.get_parsed_response(); + if (rsp->_status_code != static_cast(http::reply::status_type::ok)) { + throw std::runtime_error(format("Error: HTTP response status {}", rsp->_status_code)); + } + auto it = rsp->_headers.find("Content-Length"); if (it == rsp->_headers.end()) { throw std::runtime_error("Error: HTTP response does not contain: Content-Length\n");