I\'m in the proces of adding an interceptor to my angular 6 project. To make calls to my API, I need to add a bearer token to all calls. Unfortunately the interceptor does n
In my case i had a post method like this:
this.http.post(this.authUrl, JSON.stringify({username: username, password: password})).pipe(
map((response: any) => {
let token: any = response.token;
if (token) {
localStorage.setItem('currentUser', 'value' }));
return response;
} else {
return null;
}
}),
catchError((error:any) => {return observableThrowError(error.json().error || 'Server error')})
);
Because the map method could return null the interceptor stopt intercepting the requests made with this post method call. Don't ask me why this is so, but as soon as i replace null with say response everything started working again.