<commit_before>import { Injectable } from '@angular/core';
import { Http, XHRBackend, RequestOptions, Request, RequestOptionsArgs, Response, Headers } from '@angular/http';
import { Observable } from 'rxjs/Rx';

@Injectable()
export class HttpService extends Http {

  constructor(backend: XHRBackend, options: RequestOptions) {
    const token = localStorage.getItem('token');
    options.headers.set('Authorization', `Bearer ${token}`);
    super(backend, options);
  }

  request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
    const token = localStorage.getItem('token');

    if (typeof url === 'string') {
      if (!options) {
        options = { headers: new Headers() };
      }
      options.headers.set('Authorization', `Bearer ${token}`);
    } else {
      url.headers.set('Authorization', `Bearer ${token}`);
    }
    return super.request(url, options).catch(this.catchAuthError(this));
  }

  private catchAuthError(self: HttpService) {
    return (res: Response) => {
      if (res.status === 401 || res.status === 403) {
        console.error(res);
      }
      return Observable.throw(res);
    };
  }

}<commit_msg>auth check<commit_after>import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Http, XHRBackend, RequestOptions, Request, RequestOptionsArgs, Response, Headers } from '@angular/http';
import { Observable } from 'rxjs/Rx';

@Injectable()
export class HttpService extends Http {

  constructor(backend: XHRBackend, options: RequestOptions) {
    const token = localStorage.getItem('token');
    options.headers.set('Authorization', `Bearer ${token}`);
    super(backend, options);
  }

  request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
    const token = localStorage.getItem('token');

    if (typeof url === 'string') {
      if (!options) {
        options = { headers: new Headers() };
      }
      options.headers.set('Authorization', `Bearer ${token}`);
    } else {
      url.headers.set('Authorization', `Bearer ${token}`);
    }
    return super.request(url, options).catch(this.catchAuthError(this));
  }

  private catchAuthError(self: HttpService) {
    return (res: Response) => {
      if (res.status === 401 || res.status === 403) {
        localStorage.removeItem('token');
        location.replace('login');
        console.error(res);
      }
      return Observable.throw(res);
    };
  }

}
{'fraction_non_alphanumeric': 0.15362673186634065, 'fraction_numerical': 0.004889975550122249, 'mean_word_length': 3.694072657743786, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2324311', 'n_tokens_mistral': 722, 'n_tokens_neox': 716, 'n_words': 165}