docs »
browser-agent »
integrations »
Integrating with Angular 1.X
Angular provides an $exceptionHandler
decorator for capturing errors arising from your code. This example shows one way to plug TrackJS in to the $exceptionHandler
.
Global
Module
Legacy
angular
.module("YOUR_APP", [])
.config(["$provide", function ($provide) {
$provide.decorator("$exceptionHandler", ["$delegate", "$window", function($delegate, $window) {
return function (exception, cause) {
window.TrackJS && TrackJS.track(exception);
// In *non-production* environments you may still want the error sent to the console.
// You can delegate to the original handler (console.error) if you would like.
// Warning, this can cause double tracking of errors, so do not use in production.
// $delegate(exception, cause);
};
}]);
}]);
Copy
import angular from "angular";
import { TrackJS } from "trackjs";
angular
.module("YOUR_APP", [])
.config(["$provide", function ($provide) {
$provide.decorator("$exceptionHandler", ["$delegate", "$window", function($delegate, $window) {
return function (exception, cause) {
TrackJS.track(exception);
// In *non-production* environments you may still want the error sent to the console.
// You can delegate to the original handler (console.error) if you would like.
// Warning, this can cause double tracking of errors, so do not use in production.
// $delegate(exception, cause);
};
}]);
}]);
Copy
angular
.module("YOUR_APP", [])
.config(["$provide", function ($provide) {
$provide.decorator("$exceptionHandler", ["$delegate", "$window", function($delegate, $window) {
return function (exception, cause) {
window.trackJs && trackJs.track(exception);
// In *non-production* environments you may still want the error sent to the console.
// You can delegate to the original handler (console.error) if you would like.
// Warning, this can cause double tracking of errors, so do not use in production.
// $delegate(exception, cause);
};
}]);
}]);
Copy