From 7cce1bdcfc1d7a8e57553154705bf60c1c66d651 Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Sun, 10 Apr 2016 13:09:14 +0200
Subject: [PATCH] Fix: show the error during sync if one occurs

---
 app/js/controllers/init/sync/SyncController.js | 9 +++++----
 app/js/lib/conf/i18n/en.json                   | 1 +
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/app/js/controllers/init/sync/SyncController.js b/app/js/controllers/init/sync/SyncController.js
index 58ebc67..1847e2e 100644
--- a/app/js/controllers/init/sync/SyncController.js
+++ b/app/js/controllers/init/sync/SyncController.js
@@ -2,7 +2,7 @@
 
 var co = require('co');
 
-module.exports = ($scope, $http, $state, $timeout, $stateParams, BMA, UIUtils) => {
+module.exports = ($scope, $http, $state, $timeout, $stateParams, $translate, BMA, UIUtils) => {
 
   let syncWS = BMA.webmin.ws();
 
@@ -38,17 +38,18 @@ module.exports = ($scope, $http, $state, $timeout, $stateParams, BMA, UIUtils) =
     $scope.synchronizing = true;
     return co(function *() {
       let sp = $scope.checked_host.split(':');
+      let translatedErr = yield $translate('err.sync.interrupted');
       syncWS.on(undefined, (data) => {
         if (data.type == 'sync') {
           $scope.down_percent = 100;
           $scope.apply_percent = 100;
           $scope.sync_failed = data.value;
+          let errorMessage = data.msg && (data.msg.message || data.msg);
+          errorMessage = translatedErr + ' « ' + errorMessage + ' »';
           if (data.value === true) {
             $state.go('index');
           } else {
-            $timeout(() => {
-              window.location.href = "";
-            }, 500);
+            $state.go('error', { err: errorMessage });
           }
         } else {
           let changed = true;
diff --git a/app/js/lib/conf/i18n/en.json b/app/js/lib/conf/i18n/en.json
index 47a7ea9..77a419f 100644
--- a/app/js/lib/conf/i18n/en.json
+++ b/app/js/lib/conf/i18n/en.json
@@ -12,6 +12,7 @@
   "err.unknown": "Unknown error",
   "err.connection": "Could not connect to node",
   "err.back_index": "Get back to previous screen",
+  "err.sync.interrupted": "Sync interrupted because the following error occured:",
   "index.message.loading": "Loading...",
   "index.message.current_block": "Current block {{ number }}",
   "configuration.init.choose.title": "Initialization",
-- 
GitLab