Created
January 17, 2015 14:55
-
-
Save thm1118/e4dddcb605c396a698f4 to your computer and use it in GitHub Desktop.
angular:Catching errors with $exceptionHandler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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