Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
Handle Bing errors (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
VolkMilit authored Jan 5, 2024
1 parent 1f3c37a commit 745333d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/qonlinetranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,16 @@ void QOnlineTranslator::parseBingTranslate()
const QJsonDocument jsonResponse = QJsonDocument::fromJson(m_currentReply->readAll());
const QJsonObject responseObject = jsonResponse.array().first().toObject();

if (!jsonResponse.object().value(QStringLiteral("statusCode")).isNull()) {
const QString errorMessage = jsonResponse.object().value(QStringLiteral("errorMessage")).toString();

if (!errorMessage.isEmpty())
resetData(ServiceError, errorMessage);
else
resetData(ServiceError, tr("Error: Bing return unhandled network error"));
return;
}

if (m_sourceLang == Auto) {
const QString langCode = responseObject.value(QStringLiteral("detectedLanguage")).toObject().value(QStringLiteral("language")).toString();
m_sourceLang = language(Bing, langCode);
Expand Down

0 comments on commit 745333d

Please sign in to comment.