I'm trying to create an interceptor which should call a function to refresh the session when a 401 error is returned. This is what I have so far but it won't build and I can't work out how to do this:
intercept(
request: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
request = request.clone({
withCredentials: true
});
return next.handle(request).pipe(
catchError((error: HttpErrorResponse) => {
if (error.status === 401) {
return this.userAPI
.refreshSession(this.authService.getRefreshToken())
.then(res => {
this.authService.setAuthenticated(false);
return next.handle(request);
});
} else {
this.authService.setAuthenticated(false);
}
})
);
}
VS Code reports:
Type 'Observable<HttpSentEvent | HttpHeaderResponse | HttpProgressEvent | HttpResponse<any> | HttpUserEvent<any> | Observable<HttpEvent<any>>>' is not assignable to type 'Observable<HttpEvent<any>>'.