diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-04-25 16:07:50 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-04-25 16:07:50 +0900 |
commit | 12dc0570e2467619ef8c8b22fd2fb4a7419c92e4 (patch) | |
tree | d57c56d48088270f1322efd80f8a847a1245e115 /lib/jobs/basejob.cpp | |
parent | aa49fbcf8b20b7f9e184be41cbe3d0c13a115e6b (diff) | |
download | libquotient-12dc0570e2467619ef8c8b22fd2fb4a7419c92e4.tar.gz libquotient-12dc0570e2467619ef8c8b22fd2fb4a7419c92e4.zip |
BaseJob::doCheckReply: catch non-HTTP errors too
Diffstat (limited to 'lib/jobs/basejob.cpp')
-rw-r--r-- | lib/jobs/basejob.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp index ab07f6ad..56565859 100644 --- a/lib/jobs/basejob.cpp +++ b/lib/jobs/basejob.cpp @@ -337,13 +337,16 @@ bool checkContentType(const QByteArray& type, const QByteArrayList& patterns) BaseJob::Status BaseJob::doCheckReply(QNetworkReply* reply) const { - const auto httpCode = - reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - // QNetworkReply error codes seem to be flawed when it comes to HTTP; // see, e.g., https://github.com/QMatrixClient/libqmatrixclient/issues/200 - // The below processing is based on + // so check genuine HTTP codes. The below processing is based on // https://en.wikipedia.org/wiki/List_of_HTTP_status_codes + const auto httpCodeHeader = + reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); + if (!httpCodeHeader.isValid()) // Woah, we didn't even get HTTP headers + return { NetworkError, reply->errorString() }; + + const auto httpCode = httpCodeHeader.toInt(); if (httpCode / 100 == 2) // 2xx { if (checkContentType(reply->rawHeader("Content-Type"), |