I have a refreshing token function which gets executed inside interceptor whenever a 401 error occurs. But when refreshing token also returns 401 errors I need to logout the user but here its catchError function not executing.
Here Browser is throwing 401 error but my catchError not executing. can anyone suggest the changes or is there any implimentation problems?
Function calling refreshingToken:-
return this.loginService.getNewRefreshToken().pipe(
switchMap((tokenResponse: any) => {
if (tokenResponse) {
localStorage.setItem('jwtToken', tokenResponse.jwtToken);
localStorage.setItem('refreshToken',
tokenResponse.refreshToken.value)
localStorage.setItem('UserName', tokenResponse.userName);
this.tokenSubject.next(tokenResponse);
console.log('token refreshed');
return next.handle(this.attachAuthToken(request));
}
else return <any>this.loginService.userLogout();
refreshToken API calling:-
return this.http.post('/api/ApplicationUser/Login', loginDetails, httpOptions).pipe(
map((result: any) => {
localStorage.setItem('jwtToken', result.jwtToken);
localStorage.setItem('refreshToken', result.refreshToken.value)
localStorage.setItem('UserName', result.userName);
return result;
}),
catchError((err: any) => {
this.userLogout()
console.log('refresh error')
return throwError(err);
})
);
I have tried with manually throwing error from service, inside map operator then its working fine, but incase of network calls its not working
return this.http.post('/api/ApplicationUser/Login', loginDetails, httpOptions).pipe(
map((result: any) => {
return throwError('error');
}),
catchError((err: any) => {
this.userLogout()
console.log('refresh error')
return throwError(err);
})
);
from Rxjs catchError not getting executed
No comments:
Post a Comment