import { Injectable } from "@angular/core" ; import { Router } from "@angular/router" ; import { AuthService } from "./auth.service" ; import { ToastService } from "../toast/toast.service" ; @ Injectable ( ) export class HttpErrorHandler { constructor ( private router , private authService , private toastService ) { } handle ( error ) { if ( error . status === 401 ) { this . toastService . error ( 'Please sign in' ) ; this . authService . logout ( ) ; this . router . navigate ( [ 'login' ] ) ; } } }