Last active
August 29, 2015 14:01
-
-
Save viezel/725c16249368cc93cc20 to your computer and use it in GitHub Desktop.
bugsnag angular module
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
// bugsnag module | |
angular.module('napp-angular-bugsnag', []).run(['$rootScope', function($rootScope) { | |
$rootScope.$on('ServerException', function(evt, err) { | |
Bugsnag.user = { | |
id: napp.getUserId(), | |
name: napp.getUsername() | |
}; | |
var exception = "ErrorException"; | |
switch(err.status) { | |
case 401: | |
exception = 'NotAuthorizedException'; | |
break; | |
case 404: | |
exception = 'NotFoundException'; | |
break; | |
default: | |
break; | |
} | |
Bugsnag.notify(err.data.error.type || exception, err.data.error.message, err.config); | |
}); | |
}]); |
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
// routing | |
app.config(['$routeProvider', function($routeProvider) { | |
$routeProvider | |
.when('/myview/:id', { | |
templateUrl:"view.html", | |
controller: "viewController", | |
resolve: { | |
items: ['$q','$rootScope','API', '$route', function($q, $rootScope, API, $route){ | |
var deferred = $q.defer(); | |
API.items({id: $route.current.params.id}, | |
function(data) { | |
// on success | |
deferred.resolve(data); | |
}, function(err){ | |
// on error | |
// call Bugsnag | |
$rootScope.$broadcast('ServerException', err); | |
deferred.reject(err); | |
} | |
); | |
return deferred.promise; | |
}], | |
} | |
}) | |
// fallback | |
.otherwise({ | |
redirectTo: '/' | |
}); | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment