Created
June 29, 2016 22:21
-
-
Save foxyblocks/06e791f062af98d31c6918e1a97098bb to your computer and use it in GitHub Desktop.
Automatic angular http error tracking with Bugsnag
This file contains 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('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