PropagateUpload: Put upload error handling in one function
authorChristian Kamm <mail@ckamm.de>
Fri, 7 Jul 2017 12:12:10 +0000 (14:12 +0200)
committerckamm <mail@ckamm.de>
Wed, 12 Jul 2017 07:04:27 +0000 (09:04 +0200)
src/libsync/propagateupload.cpp
src/libsync/propagateupload.h
src/libsync/propagateuploadng.cpp
src/libsync/propagateuploadv1.cpp

index f3b0e8336b77ee034961aaadaaaa3bb40de27b5b..041a944cb8e3c9a83bd4f1eae83326b0f678f6d3 100644 (file)
@@ -522,6 +522,29 @@ void PropagateUploadFileCommon::checkResettingErrors()
     }
 }
 
+void PropagateUploadFileCommon::commonErrorHandling(AbstractNetworkJob *job)
+{
+    QByteArray replyContent;
+    QString errorString = job->errorStringParsingBody(&replyContent);
+    qCDebug(lcPropagateUpload) << replyContent; // display the XML error in the debug
+
+    if (_item->_httpErrorCode == 412) {
+        // Precondition Failed: Either an etag or a checksum mismatch.
+
+        // Maybe the bad etag is in the database, we need to clear the
+        // parent folder etag so we won't read from DB next sync.
+        propagator()->_journal->avoidReadFromDbOnNextSync(_item->_file);
+        propagator()->_anotherSyncNeeded = true;
+    }
+
+    // Ensure errors that should eventually reset the chunked upload are tracked.
+    checkResettingErrors();
+
+    SyncFileItem::Status status = classifyError(job->reply()->error(), _item->_httpErrorCode,
+        &propagator()->_anotherSyncNeeded);
+    abortWithError(status, errorString);
+}
+
 void PropagateUploadFileCommon::slotJobDestroyed(QObject *job)
 {
     _jobs.erase(std::remove(_jobs.begin(), _jobs.end(), job), _jobs.end());
index 030c43020a849910720ad6c1c4e3fd6f56bbc177..8d6b1d0b6302176c0db1bdd9e8001ee9697df454 100644 (file)
@@ -277,6 +277,11 @@ protected:
      */
     void checkResettingErrors();
 
+    /**
+     * Error handling functionality that is shared between jobs.
+     */
+    void commonErrorHandling(AbstractNetworkJob *job);
+
     // Bases headers that need to be sent with every chunk
     QMap<QByteArray, QByteArray> headers();
 };
index dd918e80b9e4cb2408e7eda91310d45df025a1a1..ce524a6308705f2e155803714ef1234724928018 100644 (file)
@@ -366,16 +366,7 @@ void PropagateUploadFileNG::slotPutFinished()
 
     if (err != QNetworkReply::NoError) {
         _item->_httpErrorCode = job->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
-        QByteArray replyContent;
-        QString errorString = job->errorStringParsingBody(&replyContent);
-        qCDebug(lcPropagateUpload) << replyContent; // display the XML error in the debug
-
-        // Ensure errors that should eventually reset the chunked upload are tracked.
-        checkResettingErrors();
-
-        SyncFileItem::Status status = classifyError(err, _item->_httpErrorCode,
-            &propagator()->_anotherSyncNeeded);
-        abortWithError(status, errorString);
+        commonErrorHandling(job);
         return;
     }
 
@@ -459,21 +450,7 @@ void PropagateUploadFileNG::slotMoveJobFinished()
     _item->_httpErrorCode = job->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
 
     if (err != QNetworkReply::NoError) {
-        if (_item->_httpErrorCode == 412) {
-            // Precondition Failed: Either an etag or a checksum mismatch.
-
-            // Maybe the bad etag is in the database, we need to clear the
-            // parent folder etag so we won't read from DB next sync.
-            propagator()->_journal->avoidReadFromDbOnNextSync(_item->_file);
-            propagator()->_anotherSyncNeeded = true;
-        }
-
-        // Ensure errors that should eventually reset the chunked upload are tracked.
-        checkResettingErrors();
-
-        SyncFileItem::Status status = classifyError(err, _item->_httpErrorCode,
-            &propagator()->_anotherSyncNeeded);
-        abortWithError(status, job->errorStringParsingBody());
+        commonErrorHandling(job);
         return;
     }
     if (_item->_httpErrorCode != 201 && _item->_httpErrorCode != 204) {
index b48b433ab752f7a7ccff8a98f5c3b851bce45ce9..b8cdd3daf845d74c5c71a41a82d2f1136a8ac7b6 100644 (file)
@@ -201,25 +201,7 @@ void PropagateUploadFileV1::slotPutFinished()
                    "It is restored and your edit is in the conflict file."))) {
             return;
         }
-        QByteArray replyContent;
-        QString errorString = job->errorStringParsingBody(&replyContent);
-        qCDebug(lcPropagateUpload) << replyContent; // display the XML error in the debug
-
-        if (_item->_httpErrorCode == 412) {
-            // Precondition Failed: Either an etag or a checksum mismatch.
-
-            // Maybe the bad etag is in the database, we need to clear the
-            // parent folder etag so we won't read from DB next sync.
-            propagator()->_journal->avoidReadFromDbOnNextSync(_item->_file);
-            propagator()->_anotherSyncNeeded = true;
-        }
-
-        // Ensure errors that should eventually reset the chunked upload are tracked.
-        checkResettingErrors();
-
-        SyncFileItem::Status status = classifyError(err, _item->_httpErrorCode,
-            &propagator()->_anotherSyncNeeded);
-        abortWithError(status, errorString);
+        commonErrorHandling(job);
         return;
     }