|
9 | 9 | ========================*/ |
10 | 10 | #include "include/restclient.h" |
11 | 11 |
|
| 12 | +#include <cstring> |
12 | 13 | #include <string> |
13 | 14 | #include <iostream> |
14 | 15 |
|
@@ -45,9 +46,9 @@ RestClient::response RestClient::get(const std::string& url) |
45 | 46 | res = curl_easy_perform(curl); |
46 | 47 | if (res != 0) |
47 | 48 | { |
48 | | - std::cerr << "Failed to query " << url << ":" |
49 | | - << std::endl << curl_easy_strerror(res) << std::endl << std::flush; |
50 | | - exit(1); |
| 49 | + ret.body = "Failed to query."; |
| 50 | + ret.code = -1; |
| 51 | + return ret; |
51 | 52 | } |
52 | 53 | long http_code = 0; |
53 | 54 | curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); |
@@ -109,9 +110,9 @@ RestClient::response RestClient::post(const std::string& url, |
109 | 110 | res = curl_easy_perform(curl); |
110 | 111 | if (res != 0) |
111 | 112 | { |
112 | | - std::cerr << "Failed to query " << url << ":" |
113 | | - << std::endl << curl_easy_strerror(res) << std::endl << std::flush; |
114 | | - exit(1); |
| 113 | + ret.body = "Failed to query."; |
| 114 | + ret.code = -1; |
| 115 | + return ret; |
115 | 116 | } |
116 | 117 | long http_code = 0; |
117 | 118 | curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); |
@@ -179,9 +180,9 @@ RestClient::response RestClient::put(const std::string& url, |
179 | 180 | res = curl_easy_perform(curl); |
180 | 181 | if (res != 0) |
181 | 182 | { |
182 | | - std::cerr << "Failed to query " << url << ":" |
183 | | - << std::endl << curl_easy_strerror(res) << std::endl << std::flush; |
184 | | - exit(1); |
| 183 | + ret.body = "Failed to query."; |
| 184 | + ret.code = -1; |
| 185 | + return ret; |
185 | 186 | } |
186 | 187 | long http_code = 0; |
187 | 188 | curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); |
@@ -228,9 +229,9 @@ RestClient::response RestClient::del(const std::string& url) |
228 | 229 | res = curl_easy_perform(curl); |
229 | 230 | if (res != 0) |
230 | 231 | { |
231 | | - std::cerr << "Failed to query " << url << ":" |
232 | | - << std::endl << curl_easy_strerror(res) << std::endl << std::flush; |
233 | | - exit(1); |
| 232 | + ret.body = "Failed to query."; |
| 233 | + ret.code = -1; |
| 234 | + return ret; |
234 | 235 | } |
235 | 236 | long http_code = 0; |
236 | 237 | curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); |
|
0 commit comments