diff --git a/src/lastfm.hpp b/src/lastfm.hpp index 33b3eeb..831dd53 100644 --- a/src/lastfm.hpp +++ b/src/lastfm.hpp @@ -44,13 +44,17 @@ public: parameters["api_sig"] = getApiSignature(parameters); std::string postBody = utils::getURLEncodedPostBody(parameters); std::string response = utils::httpRequest(api_base, "POST", postBody); - auto j = nlohmann::json::parse(response); - if (j.contains("error")) - return j["error"].get(); + try { + auto j = nlohmann::json::parse(response); + if (j.contains("error")) + return j["error"].get(); - session_token = j["session"]["key"].get(); - authenticated = true; - return LASTFM_STATUS::SUCCESS; + session_token = j["session"]["key"].get(); + authenticated = true; + return LASTFM_STATUS::SUCCESS; + } catch (...) { + return LASTFM_STATUS::UNKNOWN_ERROR; + } } LASTFM_STATUS scrobble(std::string artist, std::string track) { diff --git a/src/main.cpp b/src/main.cpp index 2e2916a..6138cd6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,7 +50,7 @@ void initLastFM(bool checkMode = false) { lastfm = new LastFM(settings.lastfm.username, settings.lastfm.password, settings.lastfm.api_key, settings.lastfm.api_secret); LastFM::LASTFM_STATUS status = lastfm->authenticate(); - if (status) + if (status && checkMode) wxMessageBox(_("Error authenticating at LastFM!"), _("PlayerLink"), wxOK | wxICON_ERROR); else if (checkMode) wxMessageBox(_("The LastFM authentication was successful."), _("PlayerLink"), wxOK | wxICON_INFORMATION);