Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@btapai/ng-error-handler

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@btapai/ng-error-handler

An error handler library for angular applications

  • 10.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ErrorHandler

How to install and use

  1. Install the package with the following script:

    npm install @btapai/ng-error-handler --save
    
  2. This package has @angular/cdk as a peer dependency. Install it as well:

    npm install @angular/cdk --save
    
  3. If your project does not use @angular/material, add the following line into your styles.css file:

    @import '~@angular/cdk/overlay-prebuilt.css';
    
  4. Import the module into your main ngModule

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { AppComponent } from './app.component';
    import { ErrorHandlerModule } from '@btapai/ng-error-handler';
    
    @NgModule({
      declarations: [AppComponent],
      imports: [
        BrowserModule,
        ErrorHandlerModule.forRoot(), // place it into the imports array
      ],
      providers: [],
      bootstrap: [AppComponent],
    })
    export class AppModule {}
    

With this setup uncaught errors will be handled by this error-handler module.

Customisation

This packages uses the Angular CDK Overlay module for creating a backdrop. If you would like to style the overlay, provide a configuration object with your custom OverlayConfig object. For possible config options check out its documentation

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { ErrorHandlerModule, ERROR_HANDLER_CONFIG, ErrorHandlerConfig } from '@btapai/ng-error-handler';

const CustomErrorHandlerConfig: ErrorHandlerConfig = {
  overlayConfig: {
    hasBackdrop: false, //
  },
};

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, ErrorHandlerModule.forRoot()],
  providers: [{ provide: ERROR_HANDLER_CONFIG, useValue: CustomErrorHandlerConfig }],
  bootstrap: [AppComponent],
})
export class AppModule {}

You can also provide custom hooks to run when an error is thrown:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { ErrorHandlerModule, ERROR_HANDLER_CONFIG, ErrorHandlerConfig } from '@btapai/ng-error-handler';
import { ThirdPartyErrorLogger } from 'third-party-error-logger';

const CustomErrorHandlerConfig: ErrorHandlerConfig = {
  errorHandlerHooks: [ThirdPartyErrorLogger.logErrorMessage],
};

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, ErrorHandlerModule.forRoot()],
  providers: [{ provide: ERROR_HANDLER_CONFIG, useValue: CustomErrorHandlerConfig }],
  bootstrap: [AppComponent],
})
export class AppModule {}

Future plans

I'd like to keep this module up-to date with Angular versions.

FAQs

Package last updated on 22 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc