I'm having an issue being able to catch the AuthHttpError that gets returned from calls to AuthHttpin angular2-jwt.
Whenever AuthHttp detects that the token is expired, it will throw AuthHttpError without sending the request to the backend. I would like to catch this error so I can log out the user. However, I can't seem to be able to catch this in Observable.catch().
Let's say I have code like this:
doRequest(url: string, params: string, jsonOptions: string) {
return this.http.post(url, params, jsonOptions)
.catch(response => {
if (response instanceof Response) {
console.info('handle server errors');
} else if (response instanceof AuthHttpError) {
console.info('handle AuthHttpError');
} else {
console.info('handle other Error')
}
return Observable.throw(response);
})
}
In this case, if the token has expired, I want the console to print "handle AuthHttpError", but it will print "handle other Error" instead. I also noticed that in this case, response.constructor.name will be "Error" instead of "AuthHttpError".
Does anyone know if there's a way to catch this error?