Handle Google Drive get file errors.
When a call to translate a file ID to a URL fails, tell the user and don't try to load the file.
This commit is contained in:
parent
06ed4a8232
commit
f81533bb58
|
@ -72,7 +72,7 @@ QStringList File::parent_ids() const {
|
||||||
ConnectResponse::ConnectResponse(QObject* parent) : QObject(parent) {}
|
ConnectResponse::ConnectResponse(QObject* parent) : QObject(parent) {}
|
||||||
|
|
||||||
GetFileResponse::GetFileResponse(const QString& file_id, QObject* parent)
|
GetFileResponse::GetFileResponse(const QString& file_id, QObject* parent)
|
||||||
: QObject(parent), file_id_(file_id) {}
|
: QObject(parent), file_id_(file_id), had_error_(false) {}
|
||||||
|
|
||||||
ListChangesResponse::ListChangesResponse(const QString& cursor, QObject* parent)
|
ListChangesResponse::ListChangesResponse(const QString& cursor, QObject* parent)
|
||||||
: QObject(parent), cursor_(cursor) {}
|
: QObject(parent), cursor_(cursor) {}
|
||||||
|
@ -165,6 +165,7 @@ void Client::GetFileFinished(GetFileResponse* response, QNetworkReply* reply) {
|
||||||
QJsonDocument document = QJsonDocument::fromJson(reply->readAll(), &error);
|
QJsonDocument document = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
qLog(Error) << "Failed to fetch file with ID" << response->file_id_;
|
qLog(Error) << "Failed to fetch file with ID" << response->file_id_;
|
||||||
|
response->had_error_ = true;
|
||||||
emit response->Finished();
|
emit response->Finished();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,7 @@ class GetFileResponse : public QObject {
|
||||||
public:
|
public:
|
||||||
const QString& file_id() const { return file_id_; }
|
const QString& file_id() const { return file_id_; }
|
||||||
const File& file() const { return file_; }
|
const File& file() const { return file_; }
|
||||||
|
bool had_error() { return had_error_; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void Finished();
|
void Finished();
|
||||||
|
@ -111,6 +112,7 @@ class GetFileResponse : public QObject {
|
||||||
GetFileResponse(const QString& file_id, QObject* parent);
|
GetFileResponse(const QString& file_id, QObject* parent);
|
||||||
QString file_id_;
|
QString file_id_;
|
||||||
File file_;
|
File file_;
|
||||||
|
bool had_error_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ListChangesResponse : public QObject {
|
class ListChangesResponse : public QObject {
|
||||||
|
|
|
@ -204,6 +204,11 @@ QUrl GoogleDriveService::GetStreamingUrlFromSongId(const QString& id) {
|
||||||
connect(response.data(), SIGNAL(Finished()), &loop, SLOT(quit()));
|
connect(response.data(), SIGNAL(Finished()), &loop, SLOT(quit()));
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
|
if (response->had_error()) {
|
||||||
|
app_->AddError(tr("Could not find Google Drive file."));
|
||||||
|
return QUrl();
|
||||||
|
}
|
||||||
|
|
||||||
QUrl url(response->file().download_url());
|
QUrl url(response->file().download_url());
|
||||||
QUrlQuery url_query(url);
|
QUrlQuery url_query(url);
|
||||||
url_query.addQueryItem("access_token", client_->access_token());
|
url_query.addQueryItem("access_token", client_->access_token());
|
||||||
|
|
|
@ -27,5 +27,7 @@ GoogleDriveUrlHandler::GoogleDriveUrlHandler(GoogleDriveService* service,
|
||||||
UrlHandler::LoadResult GoogleDriveUrlHandler::StartLoading(const QUrl& url) {
|
UrlHandler::LoadResult GoogleDriveUrlHandler::StartLoading(const QUrl& url) {
|
||||||
QString file_id = url.path();
|
QString file_id = url.path();
|
||||||
QUrl real_url = service_->GetStreamingUrlFromSongId(file_id);
|
QUrl real_url = service_->GetStreamingUrlFromSongId(file_id);
|
||||||
return LoadResult(url, LoadResult::TrackAvailable, real_url);
|
LoadResult::Type type = real_url.isValid() ? LoadResult::TrackAvailable
|
||||||
|
: LoadResult::NoMoreTracks;
|
||||||
|
return LoadResult(url, type, real_url);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue