File

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

Description

Default filter service to be used in UnhandledExceptionsHandler to filter which errors should be notified through Application?.Current?.UnhandledException.

This implementation will consider to report any error of type Exception or any error which is not an angular platform error identifed by 'NGXXXX:'

A custom service can be registered to replace this one.

Example

class MyFilterService implements UnhandledExceptionsFilterService {
  public shouldBeReported(error: any): boolean {
    return <customConditions>
  }
}

@NgModule({
  providers: [{provide: UnhandledExceptionsFilterService, useClass: MyFilterService}]
})
class MyModule {}

Index

Methods

Methods

Public shouldBeReported
shouldBeReported(er: any)

Test if an error should be notified

Parameters :
Name Type Optional
er any No
Returns : boolean

{boolean}

import { Injectable } from '@angular/core';

/**
 * Default filter service to be used in UnhandledExceptionsHandler to filter which errors should
 * be notified through Application?.Current?.UnhandledException.
 *
 * This implementation will consider to report any error of type Exception or any error which is
 * not an angular platform error identifed by 'NGXXXX:'
 *
 * A custom service can be registered to replace this one.
 *
 * @usageNotes
 * ### Example
 *
 * ```
 * class MyFilterService implements UnhandledExceptionsFilterService {
 *   public shouldBeReported(error: any): boolean {
 *     return <customConditions>
 *   }
 * }
 *
 * @NgModule({
 *   providers: [{provide: UnhandledExceptionsFilterService, useClass: MyFilterService}]
 * })
 * class MyModule {}
 * ```
 *
 * @export
 * @class UnhandledExceptionsFilterService
 */
@Injectable()
export class UnhandledExceptionsFilterService {
  /**
   * Test if an error should be notified
   *
   * @param {*} er
   * @return {*}  {boolean}
   * @memberof UnhandledExceptionsFilterService
   */
  public shouldBeReported(er: any): boolean {
    //Angular exceptions will be ignored
    return !!er && !/^\s*NG\d+:/g.test(er?.message);
  }
}

result-matching ""

    No results matching ""