diff --git a/src/requester.cpp b/src/requester.cpp index 01424f6..f080cf1 100644 --- a/src/requester.cpp +++ b/src/requester.cpp @@ -4,6 +4,7 @@ #include #include #include +#include using namespace sc; @@ -47,10 +48,18 @@ std::string requester::get(const std::string &url) { curl_easy_setopt(_h.get(), CURLOPT_URL, url.c_str()); curl_easy_setopt(_h.get(), CURLOPT_WRITEDATA, this); auto success = curl_easy_perform(_h.get()); - if (success != CURLE_OK) throw std::runtime_error("could not get remote data"); + if (success != CURLE_OK) { + std::ostringstream oss; + oss << "could not get remote data: " << curl_easy_strerror(success); + throw std::runtime_error {oss.str()}; + } long status; success = curl_easy_getinfo(_h.get(), CURLINFO_RESPONSE_CODE, &status); - if (success != CURLE_OK || status != 200) throw std::runtime_error("could not get remote data"); + if (success != CURLE_OK || status != 200) { + std::ostringstream oss; + oss << "could not get remote data (" << status << ")"; + throw std::runtime_error {oss.str()}; + } return _text; } @@ -69,6 +78,10 @@ std::string requester::post(const std::string& url, const std::string& json) { curl_easy_setopt(_h.get(), CURLOPT_WRITEDATA, &response); auto success = curl_easy_perform(_h.get()); - if (success != CURLE_OK) throw std::runtime_error("could not post data"); + if (success != CURLE_OK) { + std::ostringstream oss; + oss << "could not post data: " << curl_easy_strerror(success); + throw std::runtime_error {oss.str()}; + } return response; }