1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-12-22 14:05:18 +00:00

Loader: catch exceptions and reemit them as errors

This reduces application crashes when an invalid JSON response has been
returned.
This commit is contained in:
Chris Josten 2021-08-22 14:50:15 +02:00
parent 7f39da0b95
commit 5a24bdee59
2 changed files with 10 additions and 4 deletions

View file

@ -193,6 +193,7 @@ private:
void onRequestFinished() {
if (m_reply->error() != QNetworkReply::NoError) {
m_reply->deleteLater();
m_parsedWatcher.cancel();
//: An HTTP has occurred. First argument is replaced by QNetworkReply->errorString()
this->stopWithError(QStringLiteral("HTTP error: %1").arg(m_reply->errorString()));
}
@ -223,11 +224,15 @@ private:
}
void onResponseParsed() {
Q_ASSERT(m_parsedWatcher.isFinished());
if (m_parsedWatcher.result().has_value()) {
R result = m_parsedWatcher.result().value();
this->m_result = result;
this->m_isRunning = false;
emit this->ready();
try {
this->m_result = m_parsedWatcher.result().value();
this->m_isRunning = false;
emit this->ready();
} catch (QException &e) {
this->stopWithError(e.what());
}
} else {
this->m_isRunning = false;
}

View file

@ -361,6 +361,7 @@ void PlaybackManager::onItemUrlReceived(const QString &itemId, const QUrl &url,
void PlaybackManager::onItemErrorReceived(const QString &itemId, const QString &errorString) {
Q_UNUSED(itemId)
Q_UNUSED(errorString)
qWarning() << "Error while fetching streaming url for " << itemId << ": " << errorString;
}
} // NS ViewModel