diff --git a/CHANGELOG.md b/CHANGELOG.md index 581db69..472bb35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Change log ========== +1.4.1 +----- + +* 🎁 Improve error output while encountering API errors + 1.4.0 ----- diff --git a/src/WettergeraetDesktop/Frame.cpp b/src/WettergeraetDesktop/Frame.cpp index 0940a04..8f5f32e 100644 --- a/src/WettergeraetDesktop/Frame.cpp +++ b/src/WettergeraetDesktop/Frame.cpp @@ -29,7 +29,7 @@ void Frame::addIcaoChoice(char const icaoCode[8]) } } -Frame::Frame(const wxString& title, int argc, char * argv[]) : wxFrame(nullptr, wxID_ANY, title, wxPoint(-1, -1), wxSize(640, 480)) +Frame::Frame(const wxString& title, int argc, char * argv[]) : wxFrame(nullptr, wxID_ANY, title, wxPoint(-1, -1), wxSize(640, 520)) { this->utcDateValue.SetToCurrent(); this->SetIcon(wxICON(APPICON)); @@ -64,6 +64,8 @@ Frame::Frame(const wxString& title, int argc, char * argv[]) : wxFrame(nullptr, } SetMenuBar(menubar); + CreateStatusBar(3); + SetStatusText((this->argumentor.apikey) ? "API key present" : "No API key loaded", 0); const int labelBorder = 8; @@ -316,6 +318,7 @@ void Frame::fromInputToObject() void Frame::markAsClean() { this->saveButton->SetLabel(this->EL_BUTTON_SAVE_LABEL); + SetStatusText(wxT("Saved"), 2); } void Frame::markAsDirty() @@ -333,6 +336,7 @@ void Frame::markAsDirty() ); } this->saveButton->SetLabel(this->EL_BUTTON_SAVE_LABEL_DIRTY); + SetStatusText(wxT("Unsaved changes"), 2); } void Frame::loadMainMcf() diff --git a/src/WettergeraetLib/Argumentor.cpp b/src/WettergeraetLib/Argumentor.cpp index dd4c3ec..9622dad 100644 --- a/src/WettergeraetLib/Argumentor.cpp +++ b/src/WettergeraetLib/Argumentor.cpp @@ -3,7 +3,7 @@ #include #include -const char* Argumentor::APP_VERSION = "1.4.0"; +const char* Argumentor::APP_VERSION = "1.4.1"; #if _WIN64 const char* Argumentor::APP_TARGET = "64-bit"; #else diff --git a/src/WettergeraetLib/FetchUrl.cpp b/src/WettergeraetLib/FetchUrl.cpp index 4a43b08..8e601e6 100644 --- a/src/WettergeraetLib/FetchUrl.cpp +++ b/src/WettergeraetLib/FetchUrl.cpp @@ -56,10 +56,10 @@ std::string FetchUrl::fetch(std::string url, unsigned short fetchMode, std::stri httpHeaders = curl_slist_append(httpHeaders, "Accept: application/json"); } if (apiKey != "") { - apiKey = "X-API-Key: " + apiKey; - httpHeaders = curl_slist_append(httpHeaders, apiKey.c_str()); - apiKey = "Authorization: " + apiKey; - httpHeaders = curl_slist_append(httpHeaders, apiKey.c_str()); + auto apiKeyX = "X-API-Key: " + apiKey; + httpHeaders = curl_slist_append(httpHeaders, apiKeyX.c_str()); + auto apiKeyA = "Authorization: " + apiKey; + httpHeaders = curl_slist_append(httpHeaders, apiKeyA.c_str()); } curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); @@ -76,7 +76,22 @@ std::string FetchUrl::fetch(std::string url, unsigned short fetchMode, std::stri curl_easy_cleanup(curl); if (res == CURLE_HTTP_RETURNED_ERROR) { - throw std::invalid_argument("Invalid HTTP status code returned for " + url); + long response_code; + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); + + if (response_code == 403) { + throw std::invalid_argument("Missing or invalid API key supplied for " + url); + } + else if (response_code == 404) { + throw std::invalid_argument("API is missing for " + url); + } + else if (response_code >= 500) { + throw std::invalid_argument("Server error encountered while calling " + url); + } + else { + throw std::invalid_argument("Invalid HTTP status code " + std::to_string(response_code) + " returned for " + url); + } + } else if (res == CURLE_OPERATION_TIMEDOUT) { throw std::invalid_argument("Timeout for " + url);