Skip to content
This repository was archived by the owner on Mar 6, 2023. It is now read-only.

Commit 209b03c

Browse files
committed
Redirect the site automatically to the status page when a server error occurs. If redirect is true then we automatically wait 30 seconds before redirecting back to the previous page.
1 parent d7e128e commit 209b03c

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

src/app.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,11 @@
484484

485485
Restangular.setErrorInterceptor(function(response, deferred, responseHandler) {
486486
function handleError(response) {
487-
//if (response.status === 0 || response.status === 503) {
488-
// stateService.save(['auth.', 'status']);
489-
// $state.go('status', {redirect: true});
490-
// return true;
491-
//}
487+
if ($state.current.name !== 'status' && (response.status === 0 || response.status === 503)) {
488+
stateService.save(['auth.', 'status']);
489+
$state.go('status', { redirect: true });
490+
return true;
491+
}
492492

493493
if(response.status === 401) {
494494
stateService.save(['auth.']);

src/app/status/status-controller.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,58 @@
33

44
angular.module('app.status')
55
.controller('Status', ['$interval', '$scope', '$state', '$stateParams', 'authService', 'stateService', 'statusService', 'Restangular', function ($interval, $scope, $state, $stateParams, authService, stateService, statusService, Restangular) {
6+
var lastChecked = moment();
7+
var message = null;
68
var redirect = !!$stateParams.redirect;
79
var vm = this;
810

11+
function getMessage() {
12+
if (redirect) {
13+
return "We're sorry but the website is currently undergoing maintenance. You’ll be automatically redirected when the the maintenance is completed. Please contact support for more information.";
14+
}
15+
16+
if (!!message) {
17+
return message;
18+
}
19+
20+
return "We're sorry but the website is currently undergoing maintenance. Please contact support for more information.";
21+
}
22+
923
function updateStatus() {
1024
function updateMessage(response) {
11-
vm.message = response.status !== 0 ? response.data.message : null;
25+
if (response && response.data && response.data.message) {
26+
message = response.data.message;
27+
if (response.status !== 200) {
28+
message += ' Please contact support for more information.';
29+
}
30+
} else {
31+
message = null;
32+
}
1233
}
1334

1435
function onSuccess(response) {
15-
if (redirect) {
36+
if (redirect && moment().diff(lastChecked, 'seconds') > 30) {
1637
if (!authService.isAuthenticated()) {
1738
return $state.go('auth.login');
1839
}
1940

2041
return stateService.restore();
2142
}
2243

44+
2345
return updateMessage(response);
2446
}
2547

2648
return statusService.get().then(onSuccess, updateMessage);
2749
}
2850

29-
var interval = $interval(updateStatus, 20 * 1000);
51+
var interval = $interval(updateStatus, 30 * 1000);
3052
$scope.$on('$destroy', function () {
3153
$interval.cancel(interval);
3254
});
3355

34-
vm.message = null;
3556

57+
vm.getMessage = getMessage;
3658
updateStatus();
3759
}]);
3860
}());

src/app/status/status.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<div class="panel panel-default">
1111
<div class="panel-heading text-center"><strong>Service Status</strong></div>
1212
<div class="panel-body">
13-
{{vm.message || "We're sorry but the website is currently undergoing maintenance."}}
13+
{{vm.getMessage()}}
1414
</div>
1515
</div>
1616
</div>

0 commit comments

Comments
 (0)