CatchError is completelly ignored in 401 response.
I have httpInterceptor that handles oauth2 authentication.
Relevant code is :
import { filter, take, switchMap, map, catchError } from 'rxjs/operators';
//ommited
if (authService.hasRefreshToken()) {
return authService.doRefreshToken().pipe(switchMap(tokenResponse => {
const accessToken = tokenResponse['access_token'];
this.tokenSubject.next(accessToken);
return <Observable<HttpEvent<any>>> next.handle(this.addToken(req, accessToken));
}), catchError((err: any, caught: any) => {
console.log(err)
return Observable.throw(err);
})
)
}
AuthService class:
export class AuthService {
doRefreshToken() {
//ommited
return this.httpClient.post(environment.baseUrl + this.tokenEndpoint, null, requestOptions).pipe(
map(tokenResponse => {
this.saveToken(tokenResponse);
return tokenResponse;
}),
catchError((err: any, caught: Observable<Object>) => {
//refreshing token failed (refrech token invalid or expired) redirect to login and wipe everything
this.logout();
return Observable.throw(err);
}));
}
}
Everything works fine for 200 response, but 401 error is completely ignored. Am i using this new catchError the wrong way ?
P.S. this piece of code was working just fine with plain old catch , but now when i migrated to angular6 pipe and catchError same stuff just doesnt work.
EDIT :
Breakpoint on catchError reveals
"SyntaxError: Unexpected end of input at AuthService.push../src/app/common/auth/auth.service.ts.AuthService.doRefreshToken
Actual response from the server is :
{
"error" : "invalid_token",
"error_description" : "Refresh token expired"
}
Headers :
Request Method: POST
Status Code: 401