aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2016-07-22 18:09:44 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2016-07-22 18:09:44 +0900
commit60e83eee94bbf31ebb5151232c750c88e589c3d7 (patch)
tree0c32d4e3135ccde10d9ad1f6e4b38fe09b01535f /jobs
parente1e83e825dea1891740bd22c117d95d663fbcb50 (diff)
downloadlibquotient-60e83eee94bbf31ebb5151232c750c88e589c3d7.tar.gz
libquotient-60e83eee94bbf31ebb5151232c750c88e589c3d7.zip
Separate errors of access denial kind to a different BaseJob error code as well + stability fixes
1. Introduce ContentAccessDenied error code to BaseJob to allow clients to treat access denial errors differently from other network errors. 2. Since parseJson() overrides are responsible for calling emitResult(), the "default" BaseJob::parseJson() should call emitResult() as well. 3. Make sure BaseJob::fail() doesn't crash in absence of QNetworkReply.
Diffstat (limited to 'jobs')
-rw-r--r--jobs/basejob.cpp19
-rw-r--r--jobs/basejob.h3
2 files changed, 18 insertions, 4 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index 50c85048..2177fe9c 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -80,6 +80,7 @@ QUrlQuery BaseJob::query() const
void BaseJob::parseJson(const QJsonDocument& data)
{
+ emitResult();
}
void BaseJob::start()
@@ -120,7 +121,7 @@ void BaseJob::fail(int errorCode, QString errorString)
{
setError( errorCode );
setErrorText( errorString );
- if( d->reply->isRunning() )
+ if( d->reply && d->reply->isRunning() )
d->reply->abort();
qWarning() << "Job" << objectName() << "failed:" << errorString;
emitResult();
@@ -138,12 +139,24 @@ QNetworkReply* BaseJob::networkReply() const
void BaseJob::gotReply()
{
- if( d->reply->error() != QNetworkReply::NoError )
+ switch( d->reply->error() )
{
- qDebug() << "NetworkError:" << d->reply->error();
+ case QNetworkReply::NoError:
+ break; // All good, go to the normal flow after the switch()
+
+ case QNetworkReply::AuthenticationRequiredError:
+ case QNetworkReply::ContentAccessDenied:
+ case QNetworkReply::ContentOperationNotPermittedError:
+ qDebug() << "Content access error, Qt error code:" << d->reply->error();
+ fail( ContentAccessError, d->reply->errorString() );
+ return;
+
+ default:
+ qDebug() << "NetworkError, Qt error code:" << d->reply->error();
fail( NetworkError, d->reply->errorString() );
return;
}
+
QJsonParseError error;
QJsonDocument data = QJsonDocument::fromJson(d->reply->readAll(), &error);
if( error.error != QJsonParseError::NoError )
diff --git a/jobs/basejob.h b/jobs/basejob.h
index 98b7358b..150d39e8 100644
--- a/jobs/basejob.h
+++ b/jobs/basejob.h
@@ -47,7 +47,8 @@ namespace QMatrixClient
void start() override;
enum ErrorCode { NetworkError = KJob::UserDefinedError,
- JsonParseError, TimeoutError, UserDefinedError };
+ JsonParseError, TimeoutError, ContentAccessError,
+ UserDefinedError = 512 };
signals:
/**