Integrations

AngularJS

To track AngularJS errors you need to override original error handler like this

import angular from 'angular';

export default angular.module('exceptionOverride', []).factory('$exceptionHandler', function () {
 return function (exception) {
   const $log = angular.injector(['ng']).get('$log');

   Djaty.trackBug(exception);
   $log.error(exception)
 };
});

Then add this module to your AngularJS dependencies

angular.module('app', ['exceptionOverride', /* Your dependencies... */])
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My Website</title>
    <script src="https://cdn.djaty.com/js-sdk/djaty-javascript.js"
            djaty-api-key="YOUR_PROJECT_API_KEY_HERE">
    </script>
  </head>
  <body>
    <!--...-->
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
  </body>
</html>

Angular 2+

Include djaty-javascript.js file and configure Angular Error Handler to properly track Angular 2+ application.

If you already have a custom ErrorHandler class, just include Djaty.trackBug(err.originalError || err); into the handleError() method.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule, ErrorHandler, Injectable } from '@angular/core';

import { AppComponent } from './app.component';

declare const Djaty: {trackBug: (err: Error) => void};

export class DjatyErrorHandler implements ErrorHandler {
  handleError(err: {originalError: Error} | Error): void {
    const error = err.originalError || err;
    if (error instanceof Error) {
      Djaty.trackBug(error);
    } else {
      // Errors like 5xx (Already reported if Ajax tracking is enabled), 4xx and others.
    }
   
    throw err;
  }
}

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  providers: [{ provide: ErrorHandler, useClass: DjatyErrorHandler }],
  bootstrap: [AppComponent],
})
class AppModule { }