I create class exteded from XHRBackend to catch 401 error globaly. How can I inject my AuthService in this class to logout user when 401 error occur?
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);
}
}