mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-01-28 16:20:26 +01:00
Read Json error when possible
This commit is contained in:
parent
871bb391d6
commit
6374c77aa8
@ -21,14 +21,8 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QByteArray>
|
||||
#include <QList>
|
||||
#include <QPair>
|
||||
#include <QMap>
|
||||
#include <QSet>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QStringBuilder>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QNetworkAccessManager>
|
||||
@ -42,7 +36,6 @@
|
||||
#include "core/closure.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/network.h"
|
||||
#include "core/utilities.h"
|
||||
#include "jsonlyricsprovider.h"
|
||||
#include "lyricsfetcher.h"
|
||||
#include "auddlyricsprovider.h"
|
||||
|
@ -25,15 +25,14 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "jsonlyricsprovider.h"
|
||||
#include "lyricsfetcher.h"
|
||||
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
|
||||
class AuddLyricsProvider : public JsonLyricsProvider {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -35,19 +35,24 @@ JsonLyricsProvider::JsonLyricsProvider(const QString &name, QObject *parent) : L
|
||||
|
||||
QJsonObject JsonLyricsProvider::ExtractJsonObj(QNetworkReply *reply, const quint64 id) {
|
||||
|
||||
QString failure_reason;
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
QString failure_reason = QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||
Error(id, failure_reason);
|
||||
return QJsonObject();
|
||||
failure_reason = QString("%1 (%2)").arg(reply->errorString()).arg(reply->error());
|
||||
if (reply->error() < 200) {
|
||||
Error(id, failure_reason);
|
||||
return QJsonObject();
|
||||
}
|
||||
}
|
||||
|
||||
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 200) {
|
||||
QString failure_reason = QString("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
|
||||
Error(id, failure_reason);
|
||||
return QJsonObject();
|
||||
else if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() != 200) {
|
||||
failure_reason = QString("Received HTTP code %1").arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
|
||||
}
|
||||
|
||||
QByteArray data = reply->readAll();
|
||||
if (data.isEmpty()) {
|
||||
if (failure_reason.isEmpty()) failure_reason = "Empty reply received from server.";
|
||||
Error(id, failure_reason);
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
QJsonParseError error;
|
||||
QJsonDocument json_doc = QJsonDocument::fromJson(data, &error);
|
||||
|
Loading…
x
Reference in New Issue
Block a user