From 4b8f4ee7df5af4c9a6f4d77cac3d7c730e59c838 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Thu, 14 Nov 2013 20:44:57 +0100 Subject: [PATCH] [WO-116] Integrate error handler into all conrtollers --- src/js/controller/login-existing.js | 10 ++++++++-- src/js/controller/login-initial.js | 9 ++++++--- src/js/controller/login-new-device.js | 12 +++++++++--- src/js/controller/login.js | 19 +++++++------------ src/js/controller/navigation.js | 16 +++------------- src/js/util/error.js | 23 +++++++++++++++++++++++ src/tpl/desktop.html | 3 +-- src/tpl/login-existing.html | 5 ++++- src/tpl/login-initial.html | 6 +++++- src/tpl/login-new-device.html | 8 ++++++-- src/tpl/login.html | 3 +-- 11 files changed, 73 insertions(+), 41 deletions(-) create mode 100644 src/js/util/error.js diff --git a/src/js/controller/login-existing.js b/src/js/controller/login-existing.js index 15bacee..4214393 100644 --- a/src/js/controller/login-existing.js +++ b/src/js/controller/login-existing.js @@ -1,9 +1,15 @@ define(function(require) { 'use strict'; - var appController = require('js/app-controller'); + var appController = require('js/app-controller'), + errorUtil = require('js/util/error'); var LoginExistingCtrl = function($scope, $location) { + // global state... inherited to all child scopes + $scope.$root.state = {}; + // attach global error handler + errorUtil.attachHandler($scope); + var emailDao = appController._emailDao; $scope.buttonEnabled = true; @@ -48,8 +54,8 @@ define(function(require) { function handleError(err) { $scope.incorrect = true; $scope.buttonEnabled = true; + $scope.onError(err); $scope.$apply(); - console.error(err); } }; diff --git a/src/js/controller/login-initial.js b/src/js/controller/login-initial.js index f70e815..ddafc95 100644 --- a/src/js/controller/login-initial.js +++ b/src/js/controller/login-initial.js @@ -2,6 +2,7 @@ define(function(require) { 'use strict'; var appController = require('js/app-controller'), + errorUtil = require('js/util/error'), dl = require('js/util/download'); var LoginInitialCtrl = function($scope, $location) { @@ -10,6 +11,8 @@ define(function(require) { // global state... inherited to all child scopes $scope.$root.state = {}; + // attach global error handler + errorUtil.attachHandler($scope); states = { IDLE: 1, @@ -35,7 +38,7 @@ define(function(require) { setTimeout(function() { emailDao.unlock({}, passphrase, function(err) { if (err) { - console.error(err); + $scope.onError(err); $scope.setState(states.IDLE, true); return; } @@ -49,7 +52,7 @@ define(function(require) { // export keys from keychain emailDao._crypto.exportKeys(function(err, keys) { if (err) { - console.error(err); + $scope.onError(err); return; } @@ -63,7 +66,7 @@ define(function(require) { function onSave(err) { if (err) { - console.error(err); + $scope.onError(err); return; } $scope.proceed(); diff --git a/src/js/controller/login-new-device.js b/src/js/controller/login-new-device.js index b690494..9b8f57b 100644 --- a/src/js/controller/login-new-device.js +++ b/src/js/controller/login-new-device.js @@ -2,9 +2,15 @@ define(function(require) { 'use strict'; var angular = require('angular'), + errorUtil = require('js/util/error'), appController = require('js/app-controller'); var LoginExistingCtrl = function($scope, $location) { + // global state... inherited to all child scopes + $scope.$root.state = {}; + // attach global error handler + errorUtil.attachHandler($scope); + var emailDao = appController._emailDao; $scope.incorrect = false; @@ -23,7 +29,7 @@ define(function(require) { var userId = emailDao._account.emailAddress; emailDao._keychain.getUserKeyPair(userId, function(err, keypair) { if (err) { - console.error(err); + $scope.onError(err); return; } @@ -36,8 +42,8 @@ define(function(require) { emailDao.unlock(keypair, $scope.passphrase, function(err) { if (err) { $scope.incorrect = true; + $scope.onError(err); $scope.$apply(); - console.error(err); return; } @@ -48,7 +54,7 @@ define(function(require) { function onUnlock(err) { if (err) { - console.error(err); + $scope.onError(err); return; } diff --git a/src/js/controller/login.js b/src/js/controller/login.js index 84ffa06..6c60ce5 100644 --- a/src/js/controller/login.js +++ b/src/js/controller/login.js @@ -1,21 +1,19 @@ define(function(require) { 'use strict'; - var appController = require('js/app-controller'); + var appController = require('js/app-controller'), + errorUtil = require('js/util/error'); var LoginCtrl = function($scope, $location) { // global state... inherited to all child scopes $scope.$root.state = {}; + // attach global error handler + errorUtil.attachHandler($scope); - $scope.$root.onError = function(options) { - console.error(options); - $scope.state.dialog = { - open: true, - title: options.title || 'Error', - message: options.message || options.errMsg - }; - }; + // check for app update + appController.checkForUpdate(); + // start main application controller appController.start(function(err) { if (err) { $scope.onError(err); @@ -28,9 +26,6 @@ define(function(require) { return; } - // check for app update - appController.checkForUpdate(); - // login to imap initializeUser(); }); diff --git a/src/js/controller/navigation.js b/src/js/controller/navigation.js index 2987c77..691b20f 100644 --- a/src/js/controller/navigation.js +++ b/src/js/controller/navigation.js @@ -3,6 +3,7 @@ define(function(require) { var angular = require('angular'), appController = require('js/app-controller'), + errorUtil = require('js/util/error'), _ = require('underscore'), config = require('js/app-config').config, emailDao, senderIntervalId, @@ -15,6 +16,8 @@ define(function(require) { var NavigationCtrl = function($scope) { // global state... inherited to all child scopes $scope.$root.state = {}; + // attach global error handler + errorUtil.attachHandler($scope); emailDao = appController._emailDao; @@ -22,19 +25,6 @@ define(function(require) { // scope functions // - $scope.$root.onError = function(options) { - if (!options) { - return; - } - - console.error(options); - $scope.state.dialog = { - open: true, - title: options.title || 'Error', - message: options.message || options.errMsg - }; - }; - $scope.state.nav = { open: false, toggle: function(to) { diff --git a/src/js/util/error.js b/src/js/util/error.js new file mode 100644 index 0000000..ead6f38 --- /dev/null +++ b/src/js/util/error.js @@ -0,0 +1,23 @@ +define(function() { + 'use strict'; + + var er = {}; + + er.attachHandler = function(scope) { + scope.$root.onError = function(options) { + if (!options) { + return; + } + + console.error(options); + + scope.state.dialog = { + open: true, + title: options.title || 'Error', + message: options.errMsg || options.message + }; + }; + }; + + return er; +}); \ No newline at end of file diff --git a/src/tpl/desktop.html b/src/tpl/desktop.html index ff80720..2ab6f22 100644 --- a/src/tpl/desktop.html +++ b/src/tpl/desktop.html @@ -27,5 +27,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/tpl/login-existing.html b/src/tpl/login-existing.html index 29e3434..f561b9a 100644 --- a/src/tpl/login-existing.html +++ b/src/tpl/login-existing.html @@ -1,5 +1,4 @@
-
@@ -18,5 +17,9 @@
+ + + \ No newline at end of file diff --git a/src/tpl/login-initial.html b/src/tpl/login-initial.html index ba1e1fa..c422b3d 100644 --- a/src/tpl/login-initial.html +++ b/src/tpl/login-initial.html @@ -1,5 +1,4 @@
-
@@ -33,4 +32,9 @@
+ + + + \ No newline at end of file diff --git a/src/tpl/login-new-device.html b/src/tpl/login-new-device.html index 5dd37b4..1a7ad92 100644 --- a/src/tpl/login-new-device.html +++ b/src/tpl/login-new-device.html @@ -1,5 +1,4 @@
-
@@ -11,8 +10,13 @@
-
+
+
+ + + \ No newline at end of file diff --git a/src/tpl/login.html b/src/tpl/login.html index 2035d5e..b892c2d 100644 --- a/src/tpl/login.html +++ b/src/tpl/login.html @@ -14,5 +14,4 @@ - \ No newline at end of file + \ No newline at end of file