我创建了从XHRBackend扩展的类来捕获401错误全局。当发生401错误时,如何在此类中注入我的AuthService以注销用户?
export class CustomXHRBackend extends XHRBackend {
public createConnection(request: Request): XHRConnection {
let connection: XHRConnection = super.createConnection(request);
connection.response = connection.response
.catch(this.handleError);
return connection;
}
private handleError(error: Response | any) {
console.log(error['status']);
if(error['status'] === 401) {
console.log('Navigate to login page.');
}
return Observable.throw(error);
}
}