Download: Use the <s:message> from the reply in the error message if any
authorOlivier Goffart <ogoffart@woboq.com>
Tue, 17 Apr 2018 13:04:36 +0000 (15:04 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:57:50 +0000 (10:57 +0100)
Issue: #6459

src/libsync/propagatedownload.cpp
test/syncenginetestutils.h

index 6134f1e2a7d8e10bb424e1f06a622256fd5fe25a..9504ea6f0416090a0b2bb2fe2067138eef5aa9cd 100644 (file)
@@ -657,7 +657,7 @@ void PropagateDownloadFile::slotGetFinished()
                 &propagator()->_anotherSyncNeeded);
         }
 
-        done(status, job->errorString());
+        done(status,_item->_httpErrorCode >= 400 ? job->errorStringParsingBody() : job->errorString());
         return;
     }
 
index 40dab44874e34f94d7b48fba3aac7607ce7be33d..3b4a40f5ee1c8eb1108638be5e622637c9e52807 100644 (file)
@@ -717,8 +717,8 @@ class FakeErrorReply : public QNetworkReply
     Q_OBJECT
 public:
     FakeErrorReply(QNetworkAccessManager::Operation op, const QNetworkRequest &request,
-                   QObject *parent, int httpErrorCode)
-    : QNetworkReply{parent}, _httpErrorCode(httpErrorCode){
+                   QObject *parent, int httpErrorCode, const QByteArray &body = QByteArray())
+    : QNetworkReply{parent}, _httpErrorCode(httpErrorCode), _body(body) {
         setRequest(request);
         setUrl(request.url());
         setOperation(op);
@@ -747,9 +747,15 @@ public slots:
 
 public:
     void abort() override { }
-    qint64 readData(char *, qint64) override { return 0; }
+    qint64 readData(char *buf, qint64 max) override {
+        max = qMin<qint64>(max, _body.size());
+        memcpy(buf, _body.constData(), max);
+        _body = _body.mid(max);
+        return max;
+    }
 
     int _httpErrorCode;
+    QByteArray _body;
 };
 
 // A reply that never responds