diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-03-30 19:12:40 +0200 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-03-30 19:12:40 +0200 |
commit | 41a74ae1175b4b8723ef829270f7149c302a13c1 (patch) | |
tree | ebe5f9fa7f9b6cdccb20e4f4bcd877adb6a8f772 | |
parent | bd14854f1d4790aeea5e39ee6ceabbd690331761 (diff) | |
download | libquotient-41a74ae1175b4b8723ef829270f7149c302a13c1.tar.gz libquotient-41a74ae1175b4b8723ef829270f7149c302a13c1.zip |
BaseJob: validate the connection health before running the request
-rw-r--r-- | lib/jobs/basejob.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp index 30d60f9e..0e6a8403 100644 --- a/lib/jobs/basejob.cpp +++ b/lib/jobs/basejob.cpp @@ -211,6 +211,7 @@ void BaseJob::Private::sendRequest(bool inBackground) // some sources claim that there are issues with QT 5.8 req.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); #endif + Q_ASSERT(req.url().isValid()); for (auto it = requestHeaders.cbegin(); it != requestHeaders.cend(); ++it) req.setRawHeader(it.key(), it.value()); switch( verb ) @@ -241,16 +242,23 @@ void BaseJob::beforeAbandon(QNetworkReply*) void BaseJob::start(const ConnectionData* connData, bool inBackground) { - d->connection = connData; - d->retryTimer.setSingleShot(true); - connect (&d->retryTimer, &QTimer::timeout, - this, [this,inBackground] { sendRequest(inBackground); }); - - beforeStart(connData); - if (status().good()) - sendRequest(inBackground); - if (status().good()) - afterStart(connData, d->reply.data()); + if (connData && connData->baseUrl().isValid()) { + d->connection = connData; + d->retryTimer.setSingleShot(true); + connect(&d->retryTimer, &QTimer::timeout, this, + [this, inBackground] { sendRequest(inBackground); }); + + beforeStart(connData); + if (status().good()) + sendRequest(inBackground); + if (status().good()) + afterStart(connData, d->reply.data()); + } else { + qCCritical(d->logCat) + << "Developers, ensure the Connection is valid before using it"; + Q_ASSERT(false); + setStatus(IncorrectRequestError, tr("Invalid server connection")); + } if (!status().good()) QTimer::singleShot(0, this, &BaseJob::finishJob); } |