a4-http-error-interceptor
TypeScript icon, indicating that this package has built-in type declarations

9.0.0 • Public • Published

a4-http-error-interceptor

Angular 7 Http Error Interceptor

How-To

Install

npm install a4-http-error-interceptor

app.module.ts

  1. Add HttpErrorModule to imports of the app.module.ts.
...
import { HttpErrorModule } from 'a4-http-error-interceptor';
...

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    ...,
    HttpErrorModule,
    ...
  ],
  ...
})

Inject the service

constructor(private httpErrorService: HttpErrorService) { }

Push error handler during ngOnInit

this.httpErrorService.push(404, () => {
  // handle 404
  });
);

this.httpErrorService.push('*', () => {
  // handle all other HTTP Errors
  });
);

Pop error handler during ngOnDestroy

this.httpErrorService.pop(404);

Readme

Keywords

Package Sidebar

Install

npm i a4-http-error-interceptor

Weekly Downloads

21

Version

9.0.0

License

MIT

Unpacked Size

109 kB

Total Files

26

Last publish

Collaborators

  • cccheng