mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 15:29:42 +01:00
* 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
This commit is contained in:
parent
c4c0916827
commit
2b653da3be
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user