diff --git a/src/HTTP.cxx b/src/HTTP.cxx index c6d4930d..6a3c5559 100644 --- a/src/HTTP.cxx +++ b/src/HTTP.cxx @@ -68,15 +68,20 @@ void HTTP::initCurlRead(const std::string& url) std::string HTTP::query(const std::string& query) { CURLcode response; + long responseCode; std::string buffer; char* encodedQuery = curl_easy_escape(readHandle, query.c_str(), query.size()); auto fullUrl = mReadUrl + std::string(encodedQuery); curl_easy_setopt(readHandle, CURLOPT_URL, fullUrl.c_str()); curl_easy_setopt(readHandle, CURLOPT_WRITEDATA, &buffer); response = curl_easy_perform(readHandle); + curl_easy_getinfo(readHandle, CURLINFO_RESPONSE_CODE, &responseCode); if (response != CURLE_OK) { throw InfluxDBException("HTTP::query", curl_easy_strerror(response)); } + if (responseCode != 200) { + throw InfluxDBException("HTTP::query", "Status code: " + std::to_string(responseCode)); + } return buffer; } diff --git a/test/testQuery.cxx b/test/testQuery.cxx index aac6fad7..2b156692 100644 --- a/test/testQuery.cxx +++ b/test/testQuery.cxx @@ -3,6 +3,7 @@ #include #include "../include/InfluxDBFactory.h" +#include "../src/InfluxDBException.h" namespace influxdb { namespace test { @@ -32,5 +33,11 @@ BOOST_AUTO_TEST_CASE(failedQuery1) BOOST_CHECK_EQUAL(points.size(), 0); } +BOOST_AUTO_TEST_CASE(failedQuery2) +{ + auto influxdb = influxdb::InfluxDBFactory::Get("http://localhost:8086?db=test"); + BOOST_CHECK_THROW(influxdb->query("SELECT *from test1 WHEREhost = 'localhost' LIMIT 3"), InfluxDBException); +} + } // namespace test } // namespace influxdb