0.0.2 • Published 4 years ago

@dhl-ru/ngx-error-interceptor-snackbar v0.0.2

Weekly downloads
2
License
-
Repository
-
Last release
4 years ago

NgxErrorInterceptorSnackbar

Adding to your project interceptor that catches http errors and show snackbar with that error message.

How to use

Add module to your project. In app.module.ts add:

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

import { AppComponent } from './app.component';
import { ErrorHandlerModule } from '@dhl-ru/ngx-error-interceptor-snackbar';

const errorHandlerModuleConfig = {
  customErrorObjectProperty: ["project", "deep", "message"],
  ignoreStatuses: [400, 401]
};

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    ErrorHandlerModule.forRoot(errorHandlerModuleConfig) // If you don't want to use config, you can just pass null
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Add component to the root html. For example we can add it to app.component.html. Beneath you can see component with all possible input parameters with their default value

<dhl-error-snackbar
    [fontSize]="1em"
    [width]="300px"
    [hideInSec]="5"></dhl-error-snackbar>

Descriptions of errorHandlerModuleConfig

You can ignore http error statuses by putting them to the ignoreStatuses array (example is above).

You can tell module where to find error message by putting properties to the customErrorObjectProperty array. For example, if customErrorObjectProperty: ["project", "deep", "message"], the module will look into HttpErrorResponse.error.project.deep.message to find the error message.