From: Christian Kamm Date: Fri, 7 Jul 2017 12:12:10 +0000 (+0200) Subject: PropagateUpload: Put upload error handling in one function X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~704^2^2~48 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=5d90b48790395daf63c61045b352160060485f35;p=nextcloud-desktop.git PropagateUpload: Put upload error handling in one function --- diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index f3b0e8336..041a944cb 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -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()); diff --git a/src/libsync/propagateupload.h b/src/libsync/propagateupload.h index 030c43020..8d6b1d0b6 100644 --- a/src/libsync/propagateupload.h +++ b/src/libsync/propagateupload.h @@ -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 headers(); }; diff --git a/src/libsync/propagateuploadng.cpp b/src/libsync/propagateuploadng.cpp index dd918e80b..ce524a630 100644 --- a/src/libsync/propagateuploadng.cpp +++ b/src/libsync/propagateuploadng.cpp @@ -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) { diff --git a/src/libsync/propagateuploadv1.cpp b/src/libsync/propagateuploadv1.cpp index b48b433ab..b8cdd3daf 100644 --- a/src/libsync/propagateuploadv1.cpp +++ b/src/libsync/propagateuploadv1.cpp @@ -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; }