AppErrorEvent

February 24, 2022 ยท View on GitHub

API > Interfaces

AppErrorEvent

Description

An interface that is used when tracking application errors.

Properties

PropertyDesciption
error: ErrorThe error object being thrown.
id: stringoptional
A useful identifier for the event.
scopes?: []optional
A list of scopes to include with the event.

Example

In this example an AppErrorEvent is being tracked via a custom error handler. The event is then fed to the trackAppError method on the EventDispatchService. The objects in scopes are completely customizable and determined by consuming applications.

import { AppErrorEvent, EventDispatchService } from 'oculr-ngx';

@Injectable()
export class AppErrorHandler implements ErrorHandler {
  constructor(private eventDispatchService: EventDispatchService) {}

  handleError(error: AppError | HttpErrorResponse): void {
    const event: AppErrorEvent = {
      error,
      id: error instanceof AppError ? error.name : error.status?.toString(),
      scopes: [
        {
          // the following property is only an example
          level: 'application',
        },
      ],
    };
    this.eventDispatchService.trackAppError(event);
  }
}

Feedback

Is something not working or unclear? Please create an issue or PR.