I'm facing an issue with implementing an HTTP interceptor in my Angular project, which utilizes the Alfresco Application Development Framework (ADF) libraries. Despite configuring the interceptor, it doesn't seem to intercept the HTTP requests of the project. Even when using httpClient to make a call and displaying the response in the interceptor, I only get { type: 0 }.
Here is my interceptor code:
import { Injectable } from '@angular/core';
import {
HttpRequest,
HttpHandler,
HttpInterceptor, HttpResponse,
} from '@angular/common/http';
import { tap } from 'rxjs/operators';
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor() {}
intercept(request: HttpRequest<any>, next: HttpHandler): any {
return next.handle(request).pipe(
tap((event:HttpResponse<any>) => {
if (event instanceof HttpResponse && event.status == 401) {
console.log('Unauthorized. Reloading the page...');
}
})
);
}
}
and here is how i set the provider in the AppModule.ts
{provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true},
Any insights on why the interceptor might not be intercepting requests or suggestions on how to resolve this issue would be greatly appreciated. Thank you!