changeset 144:75a4faa219a9

Improve backup process error handling.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 24 Aug 2017 18:06:11 +0300
parents 3b904b49ce57
children 9f3c0a99bcb1
files src/main.cpp
diffstat 1 files changed, 32 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.cpp	Thu Aug 24 16:31:19 2017 +0300
+++ b/src/main.cpp	Thu Aug 24 18:06:11 2017 +0300
@@ -523,6 +523,12 @@
         this,
         SLOT(backupProgress(qint64, qint64)));
 
+    connect(
+        backupReply,
+        SIGNAL(error(QNetworkReply::NetworkError)),
+        this,
+        SLOT(backupError(QNetworkReply::NetworkError)));
+
     // Create progress dialog
     backupDialog = new QProgressDialog(
         tr("Varmuuskopioidaan tietokantaa ..."),
@@ -565,9 +571,33 @@
 {
     if (backupReply)
     {
-        slLog("PAF", QString::fromUtf8(backupReply->readAll()));
+        QVariant status = backupReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
+        if (status.isValid())
+        {
+            int code = status.toInt();
+            switch (code)
+            {
+                case 200:
+                    slLog("INFO", "Backup successful.");
+                    break;
+
+                case 403:
+                    slLog("ERROR", "Backup server authentication failed. Wrong secret or other invalid settings.");
+                    break;
+
+                default:
+                    slLog("ERROR",
+                        QStringLiteral("Backup server responded with error:\n")+
+                        QString::fromUtf8(backupReply->readAll()));
+                    break;
+            }
+        }
     }
-    slLog("INFO", "Backup finished.");
+    else
+    {
+        slLog("WARNING", "Backup finished prematurely (failed).");
+    }
+
     backupDialog->close();
 }