Skip to content

Commit

Permalink
#76 Add a default error handler to routes
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Apr 3, 2018
1 parent 5276e08 commit 49ad1cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion www/src/app/index.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 19 additions & 3 deletions www/src/app/index.run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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
);
}
});
}
Expand Down

0 comments on commit 49ad1cb

Please sign in to comment.