[Pkg-owncloud-commits] [owncloud-client] 124/175: Wizard: Show server error message if possible. #3220

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Aug 8 10:36:34 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 4c10f1e40caf5918853dda9f5dcd39296931123c
Author: Christian Kamm <kamm at incasoftware.de>
Date:   Wed Jun 3 15:35:26 2015 +0200

    Wizard: Show server error message if possible. #3220
---
 src/gui/owncloudsetupwizard.cpp |  8 +++++++-
 src/libsync/networkjobs.cpp     | 16 +++++++++++++++-
 src/libsync/networkjobs.h       |  8 ++++++++
 src/libsync/propagateupload.cpp |  6 +++---
 4 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp
index 9fa17e6..34dd5e2 100644
--- a/src/gui/owncloudsetupwizard.cpp
+++ b/src/gui/owncloudsetupwizard.cpp
@@ -267,11 +267,17 @@ void OwncloudSetupWizard::slotAuthError()
 
     // Provide messages for other errors, such as invalid credentials.
     } else if (reply->error() != QNetworkReply::NoError) {
-        errorMsg = reply->errorString();
         if (!_ocWizard->account()->credentials()->stillValid(reply)) {
             errorMsg = tr("Access forbidden by server. To verify that you have proper access, "
                           "<a href=\"%1\">click here</a> to access the service with your browser.")
                        .arg(_ocWizard->account()->url().toString());
+        } else {
+            errorMsg = reply->errorString();
+
+            QString extraMsg = extractErrorMessage(reply->readAll());
+            if (!extraMsg.isEmpty()) {
+                errorMsg.append(QString(" (%1)").arg(extraMsg));
+            }
         }
 
     // Something else went wrong, maybe the response was 200 but with invalid data.
diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp
index ed0aee9..4bdb436 100644
--- a/src/libsync/networkjobs.cpp
+++ b/src/libsync/networkjobs.cpp
@@ -851,7 +851,21 @@ bool JsonApiJob::finished()
     return true;
 }
 
+QString extractErrorMessage(const QByteArray& errorResponse)
+{
+    QXmlStreamReader reader(errorResponse);
+    reader.readNextStartElement();
+    if (reader.name() != "error") {
+        return QString::null;
+    }
 
-
+    while (!reader.atEnd() && reader.error() == QXmlStreamReader::NoError) {
+        reader.readNextStartElement();
+        if (reader.name() == QLatin1String("message")) {
+            return reader.readElementText();
+        }
+    }
+    return QString::null;
+}
 
 } // namespace OCC
diff --git a/src/libsync/networkjobs.h b/src/libsync/networkjobs.h
index 868207d..c78bc43 100644
--- a/src/libsync/networkjobs.h
+++ b/src/libsync/networkjobs.h
@@ -314,6 +314,14 @@ signals:
     void jsonRecieved(const QVariantMap &json);
 };
 
+/** Gets the SabreDAV-style error message from an error response.
+ *
+ * This assumes the response is XML with a 'error' tag that has a
+ * 'message' tag that contains the data to extract.
+ *
+ * Returns a null string if no message was found.
+ */
+QString OWNCLOUDSYNC_EXPORT extractErrorMessage(const QByteArray& errorResponse);
 
 } // namespace OCC
 
diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp
index 208e632..2bea9d5 100644
--- a/src/libsync/propagateupload.cpp
+++ b/src/libsync/propagateupload.cpp
@@ -570,9 +570,9 @@ void PropagateUploadFileQNAM::slotPutFinished()
 
         QByteArray replyContent = job->reply()->readAll();
         qDebug() << replyContent; // display the XML error in the debug
-        QRegExp rx("<s:message>(.*)</s:message>"); // Issue #1366: display server exception
-        if (rx.indexIn(QString::fromUtf8(replyContent)) != -1) {
-            errorString += QLatin1String(" (") + rx.cap(1) + QLatin1Char(')');
+        QString extraMsg = extractErrorMessage(replyContent);
+        if (!extraMsg.isEmpty()) {
+            errorString += QLatin1String(" (") + extraMsg + QLatin1Char(')');
         }
 
         if (job->reply()->hasRawHeader("OC-ErrorString")) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list