Skip to content

Commit

Permalink
Update error description (open-eid#1153)
Browse files Browse the repository at this point in the history
IB-7623

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored Feb 6, 2023
1 parent 978e403 commit 1e9f205
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 97 deletions.
79 changes: 28 additions & 51 deletions client/dialogs/MobileProgress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "Styles.h"
#include "Utils.h"
#include "dialogs/WarningDialog.h"
#include "dialogs/WaitDialog.h"

#include <common/Common.h>
#include <common/Configuration.h>
Expand Down Expand Up @@ -85,13 +84,13 @@ MobileProgress::MobileProgress(QWidget *parent)
{
const_cast<QLoggingCategory&>(MIDLog()).setEnabled(QtDebugMsg,
QFile::exists(QStringLiteral("%1/%2.log").arg(QDir::tempPath(), qApp->applicationName())));
d->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint);
d->setWindowFlag(Qt::CustomizeWindowHint);
d->setupUi(d);
d->move(parent->geometry().center() - d->geometry().center());
d->code->setBuddy(d->signProgressBar);
d->code->setFont(Styles::font(Styles::Regular, 48));
d->info->setFont(Styles::font(Styles::Regular, 14));
d->controlCode->setFont(Styles::font(Styles::Regular, 14));
d->controlCode->setFont(d->info->font());
d->signProgressBar->setFont(d->info->font());
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
const auto styleSheet = R"(QProgressBar {
Expand Down Expand Up @@ -163,71 +162,54 @@ background-color: #007aff;
qCWarning(MIDLog) << err;
stop();
d->hide();
WarningDialog dlg(err, details, d->parentWidget());
QObject::connect(&dlg, &WarningDialog::finished, &d->l, &QEventLoop::exit);
dlg.exec();
WarningDialog *dlg = WarningDialog::show(d->parentWidget(), err, details);
QObject::connect(dlg, &WarningDialog::finished, &d->l, &QEventLoop::exit);
};

switch(reply->error())
{
case QNetworkReply::NoError:
break;
case QNetworkReply::ContentNotFoundError:
returnError(d->sessionID.isEmpty() ? tr("Account not found") : tr("Session not found"));
return;
return returnError(d->sessionID.isEmpty() ? tr("Account not found") : tr("Session not found"));
case QNetworkReply::ConnectionRefusedError:
returnError(tr("%1 service has encountered technical errors. Please try again later.").arg(tr("Mobile-ID")));
return;
return returnError(tr("%1 service has encountered technical errors. Please try again later.").arg(tr("Mobile-ID")));
case QNetworkReply::SslHandshakeFailedError:
returnError(tr("SSL handshake failed. Check the proxy settings of your computer or software upgrades."));
return;
return returnError(tr("SSL handshake failed. Check the proxy settings of your computer or software upgrades."));
case QNetworkReply::TimeoutError:
case QNetworkReply::UnknownNetworkError:
returnError(tr("Failed to connect with service server. Please check your network settings or try again later."));
return;
return returnError(tr("Failed to connect with service server. Please check your network settings or try again later."));
case QNetworkReply::HostNotFoundError:
case QNetworkReply::AuthenticationRequiredError:
returnError(tr("Failed to send request. Check your %1 service access settings.").arg(tr("mobile-ID")));
return;
return returnError(tr("Failed to send request. Check your %1 service access settings.").arg(tr("mobile-ID")));
default:
{
const auto httpStatusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qCWarning(MIDLog) << httpStatusCode << "Error :" << reply->error();
switch(httpStatusCode)
{
const auto httpStatusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qCWarning(MIDLog) << httpStatusCode << "Error :" << reply->error();
if (400 == httpStatusCode)
{
break;
}
switch(httpStatusCode)
{
case 409:
returnError(tr("Failed to send request. The number of unsuccesful request from this IP address has been exceeded. Please try again later."));
break;
case 429:
returnError(tr("The limit for %1 digital signatures per month has been reached for this IP address. "
"<a href=\"https://www.id.ee/en/article/for-organisations-that-sign-large-quantities-of-documents-using-digidoc4-client/\">Additional information</a>").arg(tr("mobile-ID")));
break;
default:
returnError(tr("Failed to send request. %1 service has encountered technical errors. Please try again later.").arg(tr("Mobile-ID")), reply->errorString());
break;
}
return;
case 409:
return returnError(tr("Failed to send request. The number of unsuccesful request from this IP address has been exceeded. Please try again later."));
case 429:
return returnError(tr("The limit for %1 digital signatures per month has been reached for this IP address. "
"<a href=\"https://www.id.ee/en/article/for-organisations-that-sign-large-quantities-of-documents-using-digidoc4-client/\">Additional information</a>").arg(tr("mobile-ID")));
case 580:
return returnError(tr("Failed to send request. A valid session is associated with this personal code. "
"It is not possible to start a new signing before the current session expires. Please try again later."));
default:
return returnError(tr("Failed to send request. %1 service has encountered technical errors. Please try again later.").arg(tr("Mobile-ID")), reply->errorString());
}
}
} // switch (reply->error())
static const QStringList contentType{"application/json", "application/json;charset=UTF-8"};
static const QStringList contentType{QStringLiteral("application/json"), QStringLiteral("application/json;charset=UTF-8")};
if(!contentType.contains(reply->header(QNetworkRequest::ContentTypeHeader).toString()))
{
returnError(tr("Invalid content type header ") + reply->header(QNetworkRequest::ContentTypeHeader).toString());
return;
}
return returnError(tr("Invalid content type header ") + reply->header(QNetworkRequest::ContentTypeHeader).toString());

QByteArray data = reply->readAll();
qCDebug(MIDLog).noquote() << data;
QJsonObject result = QJsonDocument::fromJson(data, nullptr).object();
if(result.isEmpty())
{
returnError(tr("Failed to parse JSON content"));
return;
}
return returnError(tr("Failed to parse JSON content"));

if(result.contains(QStringLiteral("error")))
{
Expand Down Expand Up @@ -344,19 +326,14 @@ std::vector<unsigned char> MobileProgress::sign(const std::string &method, const
"and enter mobile-ID PIN2-code."));
d->code->setAccessibleName(QStringLiteral("%1 %2. %3").arg(d->controlCode->text(), d->code->text(), d->info->text()));

QHash<QString,QString> lang;
lang[QStringLiteral("et")] = QStringLiteral("EST");
lang[QStringLiteral("en")] = QStringLiteral("ENG");
lang[QStringLiteral("ru")] = QStringLiteral("RUS");

QByteArray data = QJsonDocument(QJsonObject::fromVariantHash({
{"relyingPartyUUID", d->UUID.isEmpty() ? QStringLiteral("00000000-0000-0000-0000-000000000000") : d->UUID},
{"relyingPartyName", d->NAME},
{"nationalIdentityNumber", d->ssid},
{"phoneNumber", d->cell},
{"hash", QByteArray::fromRawData((const char*)digest.data(), int(digest.size())).toBase64()},
{"hashType", digestMethod},
{"language", lang.value(Common::language(), QStringLiteral("EST"))},
{"language", tr("ENG")},
{"displayText", "%1"},
{"displayTextFormat", "UCS-2"}
})).toJson();
Expand Down
63 changes: 20 additions & 43 deletions client/dialogs/SmartIDProgress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "Application.h"
#include "Styles.h"
#include "Utils.h"
#include "dialogs/WaitDialog.h"
#include "dialogs/WarningDialog.h"

#include <common/Common.h>
Expand Down Expand Up @@ -95,14 +94,14 @@ SmartIDProgress::SmartIDProgress(QWidget *parent)
{
const_cast<QLoggingCategory&>(SIDLog()).setEnabled(QtDebugMsg,
QFile::exists(QStringLiteral("%1/%2.log").arg(QDir::tempPath(), qApp->applicationName())));
d->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint);
d->setWindowFlag(Qt::CustomizeWindowHint);
d->setupUi(d);
d->move(parent->geometry().center() - d->geometry().center());
d->signProgressBar->setMaximum(100);
d->code->setBuddy(d->signProgressBar);
d->code->setFont(Styles::font(Styles::Regular, 48));
d->info->setFont(Styles::font(Styles::Regular, 14));
d->controlCode->setFont(Styles::font(Styles::Regular, 14));
d->controlCode->setFont(d->info->font());
d->signProgressBar->setFont(d->info->font());
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
const auto styleSheet = R"(QProgressBar {
Expand Down Expand Up @@ -172,83 +171,61 @@ background-color: #007aff;
auto returnError = [=](const QString &err, const QString &details = {}) {
qCWarning(SIDLog) << err;
d->hide();
WarningDialog dlg(err, details, d->parentWidget());
QObject::connect(&dlg, &WarningDialog::finished, &d->l, &QEventLoop::exit);
dlg.exec();
WarningDialog *dlg = WarningDialog::show(d->parentWidget(), err, details);
QObject::connect(dlg, &WarningDialog::finished, &d->l, &QEventLoop::exit);
};

switch(reply->error())
{
case QNetworkReply::NoError:
break;
case QNetworkReply::ContentNotFoundError:
returnError(tr("Failed to sign container. Your Smart-ID transaction has expired or user account not found."));
return;
return returnError(tr("Failed to sign container. Your Smart-ID transaction has expired or user account not found."));
case QNetworkReply::ConnectionRefusedError:
returnError(tr("%1 service has encountered technical errors. Please try again later.").arg(tr("Smart-ID")));
return;
return returnError(tr("%1 service has encountered technical errors. Please try again later.").arg(tr("Smart-ID")));
case QNetworkReply::SslHandshakeFailedError:
returnError(tr("SSL handshake failed. Check the proxy settings of your computer or software upgrades."));
return;
return returnError(tr("SSL handshake failed. Check the proxy settings of your computer or software upgrades."));
case QNetworkReply::TimeoutError:
case QNetworkReply::UnknownNetworkError:
returnError(tr("Failed to connect with service server. Please check your network settings or try again later."));
return;
case QNetworkReply::ProtocolInvalidOperationError:
qCWarning(SIDLog) << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
returnError(reply->readAll());
return;
return returnError(tr("Failed to connect with service server. Please check your network settings or try again later."));
case QNetworkReply::HostNotFoundError:
case QNetworkReply::AuthenticationRequiredError:
returnError(tr("Failed to send request. Check your %1 service access settings.").arg(tr("Smart-ID")));
return;
return returnError(tr("Failed to send request. Check your %1 service access settings.").arg(tr("Smart-ID")));
default:
const auto httpStatusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qCWarning(SIDLog) << httpStatusCode << "Error :" << reply->error();
switch (httpStatusCode)
{
case 403:
returnError(tr("Failed to sign container. Check your %1 service access settings. "
return returnError(tr("Failed to sign container. Check your %1 service access settings. "
"<a href=\"https://www.id.ee/en/article/for-organisations-that-sign-large-quantities-of-documents-using-digidoc4-client/\">Additional information</a>").arg(tr("Smart-ID")));
return;
case 409:
returnError(tr("Failed to send request. The number of unsuccesful request from this IP address has been exceeded. Please try again later."));
return;
return returnError(tr("Failed to send request. The number of unsuccesful request from this IP address has been exceeded. Please try again later."));
case 429:
returnError(tr("The limit for %1 digital signatures per month has been reached for this IP address. "
return returnError(tr("The limit for %1 digital signatures per month has been reached for this IP address. "
"<a href=\"https://www.id.ee/en/article/for-organisations-that-sign-large-quantities-of-documents-using-digidoc4-client/\">Additional information</a>").arg(tr("Smart-ID")));
return;
case 471:
returnError(tr("Your Smart-ID certificate level must be qualified to sign documents in DigiDoc4 Client."));
return;
return returnError(tr("Your Smart-ID certificate level must be qualified to sign documents in DigiDoc4 Client."));
case 480:
returnError(tr("Your signing software needs an upgrade. Please update your ID software, which you can get from "
return returnError(tr("Your signing software needs an upgrade. Please update your ID software, which you can get from "
"<a href=\"https://www.id.ee/en/\">www.id.ee</a>. Additional info is available ID-helpline (+372) 666 8888."));
return;
case 580:
returnError(tr("%1 service has encountered technical errors. Please try again later.").arg(QLatin1String("Smart-ID")));
return;
return returnError(tr("Failed to send request. A valid session is associated with this personal code. "
"It is not possible to start a new signing before the current session expires. Please try again later."));
default:
returnError(tr("Failed to send request. %1 service has encountered technical errors. Please try again later.").arg(QLatin1String("Smart-ID")), reply->errorString());
return;
return returnError(tr("Failed to send request. %1 service has encountered technical errors. Please try again later.").arg(QLatin1String("Smart-ID")), reply->errorString());
}
}
static const QStringList contentType{"application/json", "application/json;charset=UTF-8"};
static const QStringList contentType{QStringLiteral("application/json"), QStringLiteral("application/json;charset=UTF-8")};
if(!contentType.contains(reply->header(QNetworkRequest::ContentTypeHeader).toString()))
{
returnError(tr("Invalid content type header ") + reply->header(QNetworkRequest::ContentTypeHeader).toString());
return;
}
return returnError(tr("Invalid content type header ") + reply->header(QNetworkRequest::ContentTypeHeader).toString());

QByteArray data = reply->readAll();
reply->deleteLater();
qCDebug(SIDLog).noquote() << data;
QJsonObject result = QJsonDocument::fromJson(data, nullptr).object();
if(result.isEmpty())
{
returnError(tr("Failed to parse JSON content"));
return;
}
return returnError(tr("Failed to parse JSON content"));
if(d->sessionID.isEmpty())
d->sessionID = result.value(QLatin1String("sessionID")).toString();
else if(result.value(QLatin1String("state")).toString() != QLatin1String("RUNNING"))
Expand Down
5 changes: 3 additions & 2 deletions client/dialogs/WarningDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ WarningDialog::WarningDialog(const QString &text, const QString &details, QWidge
, ui(new Ui::WarningDialog)
{
ui->setupUi(this);
setWindowFlags( Qt::Dialog | Qt::CustomizeWindowHint );
setWindowFlag(Qt::CustomizeWindowHint);

connect( ui->cancel, &QPushButton::clicked, this, &WarningDialog::reject );
connect( this, &WarningDialog::finished, this, &WarningDialog::close );
Expand Down Expand Up @@ -112,9 +112,10 @@ void WarningDialog::setText(const QString& text)
adjustSize();
}

void WarningDialog::show(QWidget *parent, const QString &text, const QString &details)
WarningDialog* WarningDialog::show(QWidget *parent, const QString &text, const QString &details)
{
WarningDialog *dlg = new WarningDialog(text, details, parent);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->open();
return dlg;
}
2 changes: 1 addition & 1 deletion client/dialogs/WarningDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class WarningDialog : public QDialog
void setCancelText(const QString& label);
void resetCancelStyle();
void setText(const QString& text);
static void show(QWidget *parent, const QString &text, const QString &details = {});
static WarningDialog *show(QWidget *parent, const QString &text, const QString &details = {});

private:
Ui::WarningDialog *ui;
Expand Down
8 changes: 8 additions & 0 deletions client/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,14 @@ and enter Smart-ID PIN2-code.</translation>
<source>Failed to sign container. You need to update your Smart-ID application to sign documents in DigiDoc4 Client.</source>
<translation>Failed to sign container. You need to update your Smart-ID application to sign documents in DigiDoc4 Client.</translation>
</message>
<message>
<source>Failed to send request. A valid session is associated with this personal code. It is not possible to start a new signing before the current session expires. Please try again later.</source>
<translation>Failed to send request. A valid session is associated with this personal code. It is not possible to start a new signing before the current session expires. Please try again later.</translation>
</message>
<message>
<source>ENG</source>
<translation>ENG</translation>
</message>
</context>
<context>
<name>NoCardInfo</name>
Expand Down
8 changes: 8 additions & 0 deletions client/translations/et.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,14 @@ ja sisesta nutiseadmes Smart-ID PIN2-kood.</translation>
<source>Failed to sign container. You need to update your Smart-ID application to sign documents in DigiDoc4 Client.</source>
<translation>Ümbriku allkirjastamine ebaõnnestus. DigiDoc4 kliendis allkirjastamiseks pead Smart-ID rakendust uuendama.</translation>
</message>
<message>
<source>Failed to send request. A valid session is associated with this personal code. It is not possible to start a new signing before the current session expires. Please try again later.</source>
<translation>Päringu saatmine ebaõnnestus. Selle isikukoodiga on seotud kehtiv sessioon. Enne kehtiva sessiooni aegumist ei ole võimalik uut allkirjastamist alustada. Palun proovige mõne aja pärast uuesti.</translation>
</message>
<message>
<source>ENG</source>
<translation>EST</translation>
</message>
</context>
<context>
<name>NoCardInfo</name>
Expand Down
8 changes: 8 additions & 0 deletions client/translations/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,14 @@ and enter Smart-ID PIN2-code.</source>
<source>Failed to sign container. You need to update your Smart-ID application to sign documents in DigiDoc4 Client.</source>
<translation>Не удалось подписать контейнер. Для подписания с помощью Smart-ID в программе DigiDoc4 клиент нужно обновить приложение Smart-ID.</translation>
</message>
<message>
<source>Failed to send request. A valid session is associated with this personal code. It is not possible to start a new signing before the current session expires. Please try again later.</source>
<translation>Не удалось отправить запрос. С данным персональным номером связана действующая сессия. До истечения действующей сессии невозможно начать новое подписание. Пожалуйста, попробуйте позже.</translation>
</message>
<message>
<source>ENG</source>
<translation>RUS</translation>
</message>
</context>
<context>
<name>NoCardInfo</name>
Expand Down

0 comments on commit 1e9f205

Please sign in to comment.