$exceptionHandler
demo
by Samar Pattanayak
HTML
<div ng-app="except">
<div ng-controller="cont">
</div>
</div>
JavaScript
var x = angular.module('except', []);
x.factory('$exceptionHandler', function() {
return function(exception) {
console.log(exception.message);
console.log(exception);
console.log(exception.cause);
};
});
x.config(function($provide) {
$provide.decorator("$exceptionHandler", function($delegate,$log) {
var fun = $delegate.debug;
console.log(fun);
//fun = function(exception){
//$log.warn(exception.message)
//}
//console.log($delegate);
//return $delegate;
return function(exception){
$log.debug('Default exception handler.');
$log.warn(exception.cause );
$delegate(exception);
}
})
})
x.controller('cont', function($scope,$exceptionHandler) {
$scope.click = function() {
throw {
message: 'error occurred',
cause: 202
};
};
$scope.click();
});