Skip to content

Instantly share code, notes, and snippets.

@foxyblocks
Created June 29, 2016 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxyblocks/06e791f062af98d31c6918e1a97098bb to your computer and use it in GitHub Desktop.
Save foxyblocks/06e791f062af98d31c6918e1a97098bb to your computer and use it in GitHub Desktop.
Automatic angular http error tracking with Bugsnag
angular.module('myApp').config(['$httpProvider', function ($httpProvider) {
var interceptor = ['$q', function ($q) {
function success(response) {
return response;
}
function error(response) {
// Here we decide when and how to notify Bugsnag
if (response.status != 400) { // skip notification for form validation errors
Bugsnag.notify(response.statusText, response.config.url, {response: response})
}
return $q.reject(response);
}
return function (promise) {
return promise.then(success, error);
}
}];
$httpProvider.responseInterceptors.push(interceptor);
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment