I created a classic interceptor for Angular, and now I am working on an interceptor for Syncfusion requests. While I have found a solution, I am facing a problem - I am unable to call a method in my function instance. Here is the snippet of my source code:
https://i.sstatic.net/lNXTr.png
import { DataManager, UrlAdaptor } from '@syncfusion/ej2-data';
import { CookieService } from 'ngx-cookie-service';
import { Router } from '@angular/router';
import { AppGlobalService } from '../appglobal.service';
export class CustomAdaptor extends UrlAdaptor {
router: Router;
constructor(private AppGlobal: AppGlobalService) {
super();
}
beforeSend(dm: DataManager, request: XMLHttpRequest) {
request.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
dm.dataSource.headers = [{ 'Authorization': 'Bearer ' + this.AppGlobal.GetCookie() }];
request.onloadend = function () {
if (request.status == 401) {
this.goBack();
}
}
}
goBack() {
this.router = this.AppGlobal.GetRouter();
this.router.navigate(['login']);
}
}
My main goal is to redirect to the login page if a 401 error occurs. It would be more efficient if I could directly call the login page without using the goBack method.