File

projects/wms-framework/src/lib/baseframework/UnhandledExceptionsHandler.ts

Description

Global exception handler to be used to report Exceptions to Application.Current.UnhandledException, the selection of which errors will be reported can be handled through filterService.

Errors will be handled over to the ErrorHandler.handleError too

Extends

ErrorHandler

Index

Methods

Constructor

constructor(filterService: UnhandledExceptionsFilterService)

Creates an instance of UnhandledExceptionsHandler. exceptions must be reported

Parameters :
Name Type Optional Description
filterService UnhandledExceptionsFilterService No

service to be used to validate which exceptions must be reported

Methods

handleError
handleError(er: any)

Handles the error

Parameters :
Name Type Optional
er any No
Returns : void
import { ErrorHandler, Injectable } from '@angular/core';
import { Application } from '../basecomponentmodel/Application';
import { smGetExceptionInstance } from './Exceptions';
import { UnhandledExceptionsFilterService } from './UnhandledExceptionsFilterService';

/**
 * Global exception handler to be used to report Exceptions to Application.Current.UnhandledException,
 * the selection of which errors will be reported can be handled through filterService.
 *
 * Errors will be handled over to the ErrorHandler.handleError too
 *
 * @export
 * @class UnhandledExceptionsHandler
 * @extends {ErrorHandler}
 */
@Injectable()
export class UnhandledExceptionsHandler extends ErrorHandler {
  /**
   * Creates an instance of UnhandledExceptionsHandler.
   * @param {UnhandledExceptionsFilterService} filterService service to be used to validate which
   * exceptions must be reported
   * @memberof UnhandledExceptionsHandler
   */
  constructor(private filterService: UnhandledExceptionsFilterService) {
    super();
  }

  /**
   * Handles the error
   *
   * @param {*} er
   * @memberof UnhandledExceptionsHandler
   */
  handleError(er: any) {
    super.handleError(er);

    if (
      Application?.Current?.UnhandledException?.fire &&
      this.filterService.shouldBeReported(er)
    ) {
      Application.Current.UnhandledException.fire([
        Application.Current,
        {
          ExceptionObject: smGetExceptionInstance(er),
          Handled: false,
        },
      ]);
    }
  }
}

result-matching ""

    No results matching ""