I have an interceptor which clones it request
and modifies it by headers
sending it to Authorization
a token
that I retrieve from localstorage when I make a request to my api:
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
const token: string = localStorage.getItem('token');
let req = request;
if(token){
req = request.clone( {
setHeaders: {
Authorization: `Token ${token}`
}
});
} else{
console.log("NOEXISTETOKEN")
}
return next.handle(req);
}
It works fine for me, the problem I have is that I have a service which consumes another service that has nothing to do with my api:
public getJSON(): Observable<any> {
return this.http.get(this.URL_ESQUEMA);
}
To consume this service I don't need to send it a token
but when making the request the interceptor sends it token
and when it doesn't need token
and send one it returns an error401 (Unauthorized)
How can I do so that in a request to a specific URL headers
the interceptors are not modified in order to access it without problems.
I solved it this way:
You can access it this way and do the comparison: