mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-19 12:02:44 +08:00
Added a global error handler
This commit is contained in:
parent
eb9e712f91
commit
892cc7da31
|
@ -94,7 +94,7 @@ function interpret_color(str) {
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div id="ancestor">
|
<div id="ancestor">
|
||||||
<span style="font-size: 16pt; color: #8888FF">fish</span><p id="global_error" class="error_msg"></p>
|
<span style="font-size: 16pt; color: #8888FF">fish</span><p id="global_error" class="error_msg" error-message></p>
|
||||||
<div id="parent">
|
<div id="parent">
|
||||||
<div id="tab_parent" ng-controller="main">
|
<div id="tab_parent" ng-controller="main">
|
||||||
<div ng-class="tabCssClass('colors')" id="tab_colors" ng-click="changeView('colors')">colors</div>
|
<div ng-class="tabCssClass('colors')" id="tab_colors" ng-click="changeView('colors')">colors</div>
|
||||||
|
|
|
@ -31,3 +31,39 @@ fishconfig.config(
|
||||||
redirectTo: "/colors"
|
redirectTo: "/colors"
|
||||||
})
|
})
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
/* Inspired from http://blog.tomaka17.com/2012/12/random-tricks-when-using-angularjs/ */
|
||||||
|
fishconfig.config(function($httpProvider, $compileProvider) {
|
||||||
|
var global_error_element = null;
|
||||||
|
|
||||||
|
var showMessage = function(content) {
|
||||||
|
global_error_element.text(content);
|
||||||
|
};
|
||||||
|
|
||||||
|
$httpProvider.responseInterceptors.push(function($q) {
|
||||||
|
return function(promise) {
|
||||||
|
return promise.then(function(successResponse) {
|
||||||
|
showMessage('');
|
||||||
|
return successResponse;
|
||||||
|
}, function(errorResponse) {
|
||||||
|
switch (errorResponse.status) {
|
||||||
|
case 0:
|
||||||
|
showMessage("The request received an error. Perhaps the server has shut down.");
|
||||||
|
break;
|
||||||
|
case 500:
|
||||||
|
showMessage('Server internal error: ' + errorResponse.data);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
showMessage('Error ' + errorResponse.status + ': ' + errorResponse.data);
|
||||||
|
}
|
||||||
|
return $q.reject(errorResponse);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
$compileProvider.directive('errorMessage', function() {
|
||||||
|
return {
|
||||||
|
link: function(scope, element, attrs) { global_error_element = element; }
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user