This repository was archived by the owner on Aug 11, 2020. It is now read-only.
File tree 2 files changed +12
-0
lines changed
2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -68,15 +68,20 @@ void HTTP::initCurlRead(const std::string& url)
68
68
std::string HTTP::query (const std::string& query)
69
69
{
70
70
CURLcode response;
71
+ long responseCode;
71
72
std::string buffer;
72
73
char * encodedQuery = curl_easy_escape (readHandle, query.c_str (), query.size ());
73
74
auto fullUrl = mReadUrl + std::string (encodedQuery);
74
75
curl_easy_setopt (readHandle, CURLOPT_URL, fullUrl.c_str ());
75
76
curl_easy_setopt (readHandle, CURLOPT_WRITEDATA, &buffer);
76
77
response = curl_easy_perform (readHandle);
78
+ curl_easy_getinfo (readHandle, CURLINFO_RESPONSE_CODE, &responseCode);
77
79
if (response != CURLE_OK) {
78
80
throw InfluxDBException (" HTTP::query" , curl_easy_strerror (response));
79
81
}
82
+ if (responseCode != 200 ) {
83
+ throw InfluxDBException (" HTTP::query" , " Status code: " + std::to_string (responseCode));
84
+ }
80
85
return buffer;
81
86
}
82
87
Original file line number Diff line number Diff line change 3
3
#include < boost/test/unit_test.hpp>
4
4
5
5
#include " ../include/InfluxDBFactory.h"
6
+ #include " ../src/InfluxDBException.h"
6
7
7
8
namespace influxdb {
8
9
namespace test {
@@ -32,5 +33,11 @@ BOOST_AUTO_TEST_CASE(failedQuery1)
32
33
BOOST_CHECK_EQUAL (points.size (), 0 );
33
34
}
34
35
36
+ BOOST_AUTO_TEST_CASE (failedQuery2)
37
+ {
38
+ auto influxdb = influxdb::InfluxDBFactory::Get (" http://localhost:8086?db=test" );
39
+ BOOST_CHECK_THROW (influxdb->query (" SELECT *from test1 WHEREhost = 'localhost' LIMIT 3" ), InfluxDBException);
40
+ }
41
+
35
42
} // namespace test
36
43
} // namespace influxdb
You can’t perform that action at this time.
0 commit comments