From d8b6e00fe78033b93f195893c2f75e574a892bef Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 26 Feb 2015 15:52:07 +0100 Subject: [PATCH] Propagator: Let network propagator job understand a new header OC-ErrorString This allows the server to send a readable error string in many cases --- src/libsync/propagatedownload.cpp | 11 +++++++++++ src/libsync/propagatedownload.h | 4 +--- src/libsync/propagateremotedelete.cpp | 8 +++++++- src/libsync/propagateremotemkdir.cpp | 6 +++++- src/libsync/propagateremotemove.cpp | 8 +++++++- src/libsync/propagateupload.cpp | 4 ++++ 6 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index 82923e009..712f2cad0 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -263,6 +263,17 @@ void GETFileJob::slotTimeout() reply()->abort(); } +QString GETFileJob::errorString() const +{ + if (!_errorString.isEmpty()) { + return _errorString; + } else if (reply()->hasRawHeader("OC-ErrorString")) { + return reply()->rawHeader("OC-ErrorString"); + } else { + return reply()->errorString(); + } +} + void PropagateDownloadFileQNAM::start() { if (_propagator->_abortRequested.fetchAndAddRelaxed(0)) diff --git a/src/libsync/propagatedownload.h b/src/libsync/propagatedownload.h index cc486efd0..ad71f743a 100644 --- a/src/libsync/propagatedownload.h +++ b/src/libsync/propagatedownload.h @@ -77,9 +77,7 @@ public: void giveBandwidthQuota(qint64 q); qint64 currentDownloadPosition(); - QString errorString() { - return _errorString.isEmpty() ? reply()->errorString() : _errorString; - } + QString errorString() const; SyncFileItem::Status errorStatus() { return _errorStatus; } diff --git a/src/libsync/propagateremotedelete.cpp b/src/libsync/propagateremotedelete.cpp index ecae78c3f..8cbcf7251 100644 --- a/src/libsync/propagateremotedelete.cpp +++ b/src/libsync/propagateremotedelete.cpp @@ -38,7 +38,13 @@ void DeleteJob::start() QString DeleteJob::errorString() { - return _timedout ? tr("Connection timed out") : reply()->errorString(); + if (_timedout) { + return tr("Connection timed out"); + } else if (reply()->hasRawHeader("OC-ErrorString")) { + return reply()->rawHeader("OC-ErrorString"); + } else { + return reply()->errorString(); + } } bool DeleteJob::finished() diff --git a/src/libsync/propagateremotemkdir.cpp b/src/libsync/propagateremotemkdir.cpp index 431d4e615..1b724dab3 100644 --- a/src/libsync/propagateremotemkdir.cpp +++ b/src/libsync/propagateremotemkdir.cpp @@ -58,7 +58,11 @@ void PropagateRemoteMkdir::slotMkcolJobFinished() // This happens when the directory already exist. Nothing to do. } else if (err != QNetworkReply::NoError) { SyncFileItem::Status status = classifyError(err, _item._httpErrorCode); - done(status, _job->reply()->errorString()); + auto errorString = _job->reply()->errorString(); + if (_job->reply()->hasRawHeader("OC-ErrorString")) { + errorString = _job->reply()->rawHeader("OC-ErrorString"); + } + done(status, errorString); return; } else if (_item._httpErrorCode != 201) { // Normaly we expect "201 Created" diff --git a/src/libsync/propagateremotemove.cpp b/src/libsync/propagateremotemove.cpp index e45affee3..600bbb39d 100644 --- a/src/libsync/propagateremotemove.cpp +++ b/src/libsync/propagateremotemove.cpp @@ -43,7 +43,13 @@ void MoveJob::start() QString MoveJob::errorString() { - return _timedout ? tr("Connection timed out") : reply()->errorString(); + if (_timedout) { + return tr("Connection timed out"); + } else if (reply()->hasRawHeader("OC-ErrorString")) { + return reply()->rawHeader("OC-ErrorString"); + } else { + return reply()->errorString(); + } } bool MoveJob::finished() diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index c3f50f3a5..848e5383b 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -475,6 +475,10 @@ void PropagateUploadFileQNAM::slotPutFinished() errorString += QLatin1String(" (") + rx.cap(1) + QLatin1Char(')'); } + if (job->reply()->hasRawHeader("OC-ErrorString")) { + errorString = job->reply()->rawHeader("OC-ErrorString"); + } + if (_item._httpErrorCode == 412) { // Precondition Failed: 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.