Skip to content

Instantly share code, notes, and snippets.

@thm1118
Created January 17, 2015 14:55
Show Gist options
  • Save thm1118/e4dddcb605c396a698f4 to your computer and use it in GitHub Desktop.
Save thm1118/e4dddcb605c396a698f4 to your computer and use it in GitHub Desktop.
angular:Catching errors with $exceptionHandler
angular.module('app', [])
.factory('$exceptionHandler', function ($injector) {
return function (exception, cause) {
var $rootScope = $injector.get('$rootScope');
$rootScope.errors = $rootScope.errors || [];
$rootScope.errors.push(exception.message);
console.log($rootScope.errors);
}
})
.run(function ($http) {
function onSuccess (result) {
console.log('hooray data!');
console.log(result.data.length, 'repos found');
result.count();
}
function onFailure (info) {
console.log('boo error :(');
console.log(info);
}
$http.get('https://api.github.com/users/bclinkinbeard/repos')
.then(onSuccess, onFailure);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment