Having trouble handling cancelled requests in my http interceptor. Despite trying various methods from SO, I can't seem to catch it.
Here is an example of how my interceptor looks:
public intercept(req: HttpRequest<any>, next: HttpHandler) {
const xyz = this._cookieService.get('xyz');
const abc = this._cookieService.get('abc');
let authReq;
if (jwt === "undefined" || jwt === undefined) {
authReq = req.clone({ headers: req.headers.set('Authorization', xyz) });
} else {
authReq = req.clone({setHeaders: { Authorization: 'bearer ' + abc } });
}
return next
.handle(authReq)
.pipe(
catchError((err: HttpErrorResponse) => this.catchErrorHandler(err))
);
}
I've experimented with the do
and finalize
methods but still facing issues. Whenever my authentication expires, subsequent requests start failing one by one, causing the page to break. I'm looking for a solution in code to prevent this happening.
Some methods I've tried: