I have an auth-interceptor.service.ts to handle the requests
import {Injectable} from \'@angular/core\';
import {HttpErrorResponse, HttpEvent, Ht
the above @bryan60 answer is works fine , if any one facing issue like me with catch the error in below line
return next.handle(authReq).catch(x=> this.handleAuthError(x));
using do() handle the error(if you face issue with catch())
import 'rxjs/add/operator/do';
return next.handle(authReq)
.do(
success => {/*todo*/},
err => {this.handleAuthError(authReq)}
);
}
handleAuthError(err: any) {
if(err.status === 401 || err.status === 403) {
this.storageService.clear();
window.location.href = '/home';
}
}
I hope this is help someone.