Add feedback on login errors
There was no feedback on any login errors when a user provided a wrong url, username, password or a disabled API. This commit adds feedback to the user in this cases. Fixes #15
This commit is contained in:
parent
4bb5610f7f
commit
f025ad4d2a
3 changed files with 40 additions and 10 deletions
|
|
@ -88,23 +88,35 @@ void TinyTinyRSSLogin::reply()
|
|||
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
|
||||
|
||||
if (reply) {
|
||||
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
|
||||
QString jsonString = QString(reply->readAll());
|
||||
QJsonDocument json = QJsonDocument::fromJson(jsonString.toUtf8());
|
||||
mSessionId = json.object().value("content").toObject().value("session_id").toString();
|
||||
if(json.object().value("content").toObject().value("error").toString().length() > 0) {
|
||||
|
||||
emit sessionIdChanged(mSessionId);
|
||||
mLoginError = json.object().value("content").toObject().value("error").toString();
|
||||
qWarning() << mLoginError;
|
||||
emit loginErrorChanged(mLoginError);
|
||||
|
||||
QSettings settings;
|
||||
settings.setValue("sessionId", mSessionId);
|
||||
settings.setValue("serverUrl", mServerUrl);
|
||||
settings.sync();
|
||||
} else {
|
||||
mSessionId = json.object().value("content").toObject().value("session_id").toString();
|
||||
|
||||
emit sessionIdChanged(mSessionId);
|
||||
|
||||
QSettings settings;
|
||||
settings.setValue("sessionId", mSessionId);
|
||||
settings.setValue("serverUrl", mServerUrl);
|
||||
settings.sync();
|
||||
}
|
||||
} else {
|
||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
//do some error management
|
||||
qWarning() << "HTTP error: " << httpStatus << " :: " << reply->error();
|
||||
mLoginError = "HTTP error: "
|
||||
+ reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString()
|
||||
+ " :: "
|
||||
+ reply->errorString();
|
||||
qWarning() << mLoginError;
|
||||
|
||||
emit loginErrorChanged(mLoginError);
|
||||
}
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue