diff --git a/CHANGELOG.md b/CHANGELOG.md index 94886ce..b5e09b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Change log ========== +1.2.7 +----- + +* 💊 Fix error handling of HTTP requests + 1.2.6 ----- diff --git a/docs/configuration.md b/docs/configuration.md index 421c638..8e52cc5 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -3,7 +3,7 @@ For more information about command line options, call the command line variant of this tool with `--help` appended to it. -There is also a [source code documentation on command-line parameters](https://github.com/fboes/aerofly-wettergeraet/blob/master/src/WettergeraetLib/Argumentor.cpp#L20) applicable for the command-line as well as the desktop variant of this tool. +There is also a [source code documentation on command-line parameters](https://github.com/fboes/aerofly-wettergeraet/blob/master/src/WettergeraetLib/Argumentor.cpp#L65) applicable for the command-line as well as the desktop variant of this tool. To append parameters to the desktop application, right-click your desktop icon, select "Properties" and append the parameter(s) to the shortcut's target. diff --git a/src/WettergeraetLib/FetchUrl.cpp b/src/WettergeraetLib/FetchUrl.cpp index 72f98c3..5523003 100644 --- a/src/WettergeraetLib/FetchUrl.cpp +++ b/src/WettergeraetLib/FetchUrl.cpp @@ -66,6 +66,7 @@ std::string FetchUrl::fetch(std::string url, unsigned short fetchMode, std::stri curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, httpHeaders); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L); + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L); //s // Do request res = curl_easy_perform(curl); @@ -75,10 +76,21 @@ std::string FetchUrl::fetch(std::string url, unsigned short fetchMode, std::stri if (res == CURLE_HTTP_RETURNED_ERROR) { throw std::invalid_argument("Invalid HTTP status code returned for " + url); } + else if (res == CURLE_OPERATION_TIMEDOUT) { + throw std::invalid_argument("Timeout for " + url); + } + else if (res != CURLE_OK) { + throw std::invalid_argument(curl_easy_strerror(res)); + } - if (buffer != "") { - return (fetchMode == FetchUrl::MODE_JSON) ? this->parseJson(buffer) : buffer; + if (fetchMode == FetchUrl::MODE_JSON) { + buffer = this->parseJson(buffer); } + if (buffer == "") { + throw std::invalid_argument("Empty or invalid response returned for " + url); + } + + return buffer; } throw std::invalid_argument("Could no initiate CURL");