Skip to content

Commit 36be257

Browse files
committed
- fix lastfm crash if internet is not present
1 parent 958def7 commit 36be257

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/lastfm.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ class LastFM {
4444
parameters["api_sig"] = getApiSignature(parameters);
4545
std::string postBody = utils::getURLEncodedPostBody(parameters);
4646
std::string response = utils::httpRequest(api_base, "POST", postBody);
47-
auto j = nlohmann::json::parse(response);
48-
if (j.contains("error"))
49-
return j["error"].get<LASTFM_STATUS>();
47+
try {
48+
auto j = nlohmann::json::parse(response);
49+
if (j.contains("error"))
50+
return j["error"].get<LASTFM_STATUS>();
5051

51-
session_token = j["session"]["key"].get<std::string>();
52-
authenticated = true;
53-
return LASTFM_STATUS::SUCCESS;
52+
session_token = j["session"]["key"].get<std::string>();
53+
authenticated = true;
54+
return LASTFM_STATUS::SUCCESS;
55+
} catch (...) {
56+
return LASTFM_STATUS::UNKNOWN_ERROR;
57+
}
5458
}
5559

5660
LASTFM_STATUS scrobble(std::string artist, std::string track) {

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void initLastFM(bool checkMode = false) {
5050
lastfm = new LastFM(settings.lastfm.username, settings.lastfm.password, settings.lastfm.api_key,
5151
settings.lastfm.api_secret);
5252
LastFM::LASTFM_STATUS status = lastfm->authenticate();
53-
if (status)
53+
if (status && checkMode)
5454
wxMessageBox(_("Error authenticating at LastFM!"), _("PlayerLink"), wxOK | wxICON_ERROR);
5555
else if (checkMode)
5656
wxMessageBox(_("The LastFM authentication was successful."), _("PlayerLink"), wxOK | wxICON_INFORMATION);

0 commit comments

Comments
 (0)