Angular 2 - Dependency injection in extended class

34 Views Asked by At

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);
  }
}
0

There are 0 best solutions below