From 2b653da3be9c1160fe7d9e29b5c198e4380e3a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Gabriel=20Lima?= Date: Sun, 30 Dec 2012 21:25:33 -0300 Subject: [PATCH] * Checking the reply status during the last.fm authentication process The last.fm API returns "ok" on the status attribute of the reply if the authentication succeeded and "failed" otherwise [1]. So this patch verifies if the status returned is "ok" to proceed with the authentication. This patch also improves the message displayed in the log when an authentication error occurs. Now the error message returned by the server is printed out even when the QNetworkReply::error() != NoError (the message retuned by the server is a lot more informative). [1] - http://www.lastfm.it/api/show/auth.getMobileSession --- .../accounts/lastfm/LastFmInfoPlugin.cpp | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/libtomahawk/accounts/lastfm/LastFmInfoPlugin.cpp b/src/libtomahawk/accounts/lastfm/LastFmInfoPlugin.cpp index a69bcab13..9edbda48e 100644 --- a/src/libtomahawk/accounts/lastfm/LastFmInfoPlugin.cpp +++ b/src/libtomahawk/accounts/lastfm/LastFmInfoPlugin.cpp @@ -941,30 +941,29 @@ LastFmInfoPlugin::onAuthenticated() return; } - if ( authJob->error() == QNetworkReply::NoError ) + lastfm::XmlQuery lfm; + lfm.parse( authJob->readAll() ); + if ( authJob->error() == QNetworkReply::NoError && lfm.attribute("status") == "ok" ) { - lastfm::XmlQuery lfm; - lfm.parse( authJob->readAll() ); + lastfm::ws::SessionKey = lfm[ "session" ][ "key" ].text(); + m_account.data()->setSessionKey( lastfm::ws::SessionKey.toLatin1() ); - if ( lfm.children( "error" ).size() > 0 ) - { - tLog() << "Error from authenticating with Last.fm service:" << lfm.text(); - m_account.data()->setSessionKey( QByteArray() ); - } - else - { - lastfm::ws::SessionKey = lfm[ "session" ][ "key" ].text(); - - m_account.data()->setSessionKey( lastfm::ws::SessionKey.toLatin1() ); - -// qDebug() << "Got session key from last.fm"; - if ( m_account.data()->scrobble() ) - m_scrobbler = new lastfm::Audioscrobbler( "thk" ); - } + if ( m_account.data()->scrobble() ) + m_scrobbler = new lastfm::Audioscrobbler( "thk" ); } else { - tLog() << "Got error in Last.fm authentication job:" << authJob->errorString(); + m_account.data()->setSessionKey( QByteArray() ); + + QString error = "Got error in Last.fm authentication job"; + if ( lfm.children( "error" ).size() > 0 ) + error += ": " + lfm.text(); + else if ( authJob->error() != QNetworkReply::NoError ) + error += ": " + authJob->errorString(); + else + error += "."; + + tLog() << error.simplified(); } authJob->deleteLater();