Skip to content

Commit

Permalink
Improve error output while encountering API errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fboes committed Nov 13, 2019
1 parent 50815e2 commit b0d8226
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change log
==========

1.4.1
-----

* 🎁 Improve error output while encountering API errors

1.4.0
-----

Expand Down
6 changes: 5 additions & 1 deletion src/WettergeraetDesktop/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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()
Expand All @@ -333,6 +336,7 @@ void Frame::markAsDirty()
);
}
this->saveButton->SetLabel(this->EL_BUTTON_SAVE_LABEL_DIRTY);
SetStatusText(wxT("Unsaved changes"), 2);
}

void Frame::loadMainMcf()
Expand Down
2 changes: 1 addition & 1 deletion src/WettergeraetLib/Argumentor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <sstream>
#include <iterator>

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
Expand Down
25 changes: 20 additions & 5 deletions src/WettergeraetLib/FetchUrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand Down

0 comments on commit b0d8226

Please sign in to comment.