- fix lastfm crash if internet is not present

This commit is contained in:
EinTim23 2025-05-13 13:41:34 +02:00
parent 958def7527
commit 36be257462
2 changed files with 11 additions and 7 deletions

View File

@ -44,6 +44,7 @@ public:
parameters["api_sig"] = getApiSignature(parameters); parameters["api_sig"] = getApiSignature(parameters);
std::string postBody = utils::getURLEncodedPostBody(parameters); std::string postBody = utils::getURLEncodedPostBody(parameters);
std::string response = utils::httpRequest(api_base, "POST", postBody); std::string response = utils::httpRequest(api_base, "POST", postBody);
try {
auto j = nlohmann::json::parse(response); auto j = nlohmann::json::parse(response);
if (j.contains("error")) if (j.contains("error"))
return j["error"].get<LASTFM_STATUS>(); return j["error"].get<LASTFM_STATUS>();
@ -51,6 +52,9 @@ public:
session_token = j["session"]["key"].get<std::string>(); session_token = j["session"]["key"].get<std::string>();
authenticated = true; authenticated = true;
return LASTFM_STATUS::SUCCESS; return LASTFM_STATUS::SUCCESS;
} catch (...) {
return LASTFM_STATUS::UNKNOWN_ERROR;
}
} }
LASTFM_STATUS scrobble(std::string artist, std::string track) { LASTFM_STATUS scrobble(std::string artist, std::string track) {

View File

@ -50,7 +50,7 @@ void initLastFM(bool checkMode = false) {
lastfm = new LastFM(settings.lastfm.username, settings.lastfm.password, settings.lastfm.api_key, lastfm = new LastFM(settings.lastfm.username, settings.lastfm.password, settings.lastfm.api_key,
settings.lastfm.api_secret); settings.lastfm.api_secret);
LastFM::LASTFM_STATUS status = lastfm->authenticate(); LastFM::LASTFM_STATUS status = lastfm->authenticate();
if (status) if (status && checkMode)
wxMessageBox(_("Error authenticating at LastFM!"), _("PlayerLink"), wxOK | wxICON_ERROR); wxMessageBox(_("Error authenticating at LastFM!"), _("PlayerLink"), wxOK | wxICON_ERROR);
else if (checkMode) else if (checkMode)
wxMessageBox(_("The LastFM authentication was successful."), _("PlayerLink"), wxOK | wxICON_INFORMATION); wxMessageBox(_("The LastFM authentication was successful."), _("PlayerLink"), wxOK | wxICON_INFORMATION);