From 49ad1cb7534ecfa4acf447091f37f0d99ad76a5f Mon Sep 17 00:00:00 2001 From: Nabil Adouani Date: Tue, 3 Apr 2018 17:02:29 +0200 Subject: [PATCH] #76 Add a default error handler to routes --- www/src/app/index.config.js | 2 +- www/src/app/index.run.js | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/www/src/app/index.config.js b/www/src/app/index.config.js index 458f61fbf..c4396425d 100755 --- a/www/src/app/index.config.js +++ b/www/src/app/index.config.js @@ -15,7 +15,7 @@ function config( $httpProvider.defaults.xsrfCookieName = 'CORTEX-XSRF-TOKEN'; $httpProvider.defaults.xsrfHeaderName = 'X-CORTEX-XSRF-TOKEN'; - $logProvider.debugEnabled(true); + $logProvider.debugEnabled(false); if (NODE_ENV === 'production') { $logProvider.debugEnabled(false); diff --git a/www/src/app/index.run.js b/www/src/app/index.run.js index 552c29ac9..a8b1ed823 100755 --- a/www/src/app/index.run.js +++ b/www/src/app/index.run.js @@ -2,7 +2,15 @@ import _ from 'lodash/core'; -function runBlock($log, $q, $transitions, $state, AuthService, Roles) { +function runBlock( + $log, + $q, + $transitions, + $state, + AuthService, + Roles, + NotificationService +) { 'ngInject'; $transitions.onSuccess({}, transition => { @@ -44,10 +52,18 @@ function runBlock($log, $q, $transitions, $state, AuthService, Roles) { return; } - if (transition.error().detail.status === 520) { + let status = transition.error().detail; + + if (status === 520) { $state.go('maintenance'); - } else if (transition.error().detail.status === 401) { + } else if (status === 401) { $state.go('login'); + } else { + NotificationService.handleError( + 'Error', + transition.error().detail.data, + status + ); } }); }