In my interceptor i want to put a pipe on response and make logout if the response statusCode is 401 but the problem is when i put a catchError the observable is not of type HttpEvent and the intercept function expects the return of that type?
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const authToken = `Agency ${this.auth.token}`;
const requestWithHeaders = req.clone({ setHeaders: {'Content-Type': 'application/json'}});
if (!!this.auth.token) {
const authReq = requestWithHeaders.clone({ setHeaders: { Authorization: authToken} });
return next.handle(authReq).pipe(
catchError(er => {
if (er.status === 401) {
this.auth.logout();
}
return er;
})
);
} else {
return next.handle(requestWithHeaders);
}
}
}.