Commit d0dbdad7 authored by Swapnil Tripathi's avatar Swapnil Tripathi Committed by Bart De Vries
Browse files

Error handling for PodcastSearchModel

parent fc99ec59
Pipeline #71325 passed with stage
in 7 minutes and 41 seconds
......@@ -52,6 +52,8 @@ QString Error::description() const
return i18n("Update Not Allowed on Metered Connection");
case Error::Type::InvalidMedia:
return i18n("Invalid Media File");
case Error::Type::DiscoverError:
return i18n("Nothing Found");
default:
return QString();
}
......@@ -68,6 +70,8 @@ int Error::typeToDb(Error::Type type)
return 2;
case Error::Type::InvalidMedia:
return 3;
case Error::Type::DiscoverError:
return 4;
default:
return -1;
}
......@@ -84,6 +88,8 @@ Error::Type Error::dbToType(int value)
return Error::Type::MeteredNotAllowed;
case 3:
return Error::Type::InvalidMedia;
case 4:
return Error::Type::DiscoverError;
default:
return Error::Type::Unknown;
}
......
......@@ -21,6 +21,7 @@ public:
MediaDownload,
MeteredNotAllowed,
InvalidMedia,
DiscoverError,
};
Q_ENUM(Type)
......
......@@ -40,6 +40,5 @@ Q_SIGNALS:
private:
explicit ErrorLogModel();
QList<Error *> m_errors;
};
......@@ -136,6 +136,7 @@ void PodcastSearchModel::search(const QString &text)
// TODO: Make this more urlsafe
safeText.replace(QLatin1Char(' '), QLatin1Char('+'));
QNetworkRequest request(QUrl(QStringLiteral("https://api.podcastindex.org/api/1.0/search/byterm?q=%1").arg(text)));
QString url = QStringLiteral("https://api.podcastindex.org/api/1.0/search/byterm?q=%1").arg(text);
request.setRawHeader("X-Auth-Key", "BLVCJJSWUJGD3WJQSZ56");
auto time = QDateTime::currentDateTime().toSecsSinceEpoch();
request.setRawHeader("X-Auth-Date", QString::number(time).toLatin1());
......@@ -146,10 +147,15 @@ void PodcastSearchModel::search(const QString &text)
auto hash = QCryptographicHash::hash(hashString.toLatin1(), QCryptographicHash::Sha1);
request.setRawHeader("Authorization", hash.toHex());
auto reply = Fetcher::instance().get(request);
// TODO: error handling
connect(reply, &QNetworkReply::finished, this, [=]() {
beginResetModel();
m_data = QJsonDocument::fromJson(reply->readAll()).object();
endResetModel();
if(reply->error())
{
ErrorLogModel::instance().monitorErrorMessages(Error::Type::DiscoverError, url, QString(), reply->error(), reply->errorString(), url);
}
else {
beginResetModel();
m_data = QJsonDocument::fromJson(reply->readAll()).object();
endResetModel();
}
});
}
......@@ -13,6 +13,7 @@
#include <QVariant>
#include "feed.h"
#include "errorlogmodel.h"
class PodcastSearchModel : public QAbstractListModel
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment