<commit_before>import {Injectable} from "@angular/core";
import {Observable} from "rxjs/Observable";
import {Headers, RequestOptions, Http, Response} from "@angular/http";
import {isNullOrUndefined} from "util";

@Injectable()
export class RestService {
  http: Http;
  protocol = 'http://';
  apiDomainName = 'localhost';
  apiPort = '3000';
  static headers: Headers;

  constructor(http: Http) {
    this.http = http;
  }

  /**
   * Return the URL of the REST API. It always ends with a '/'
   * @returns {string} example: localhost:3000/v1/
   */
  getBaseURL(): string {
    return this.protocol + this.apiDomainName + ':' + this.apiPort + '/';
  }

  /**
   * Return the base URL plus the given path
   * @param path a path (not starting with a '/')
   * @param parameters map of parameters
   * @returns {string}
   */
  getFullURL(path: String, parameters?: Map<String, String>): string {
    let fullURL = this.getBaseURL() + path;
    if (!isNullOrUndefined(parameters)) {
      fullURL += '?';
      parameters.forEach((value: String, key: String) => {
        fullURL += key + '=' + value + '&';
      });
    }
    return fullURL;
  }

  getHeaders(): RequestOptions {
    return new RequestOptions({headers: RestService.headers});
  }

  /**
   * Return a simple headers options for JSON content
   * @returns {Headers}
   */
  getHeadersForJSON(): RequestOptions {
    let json_headers = new Headers(RestService.headers);
    json_headers.append('Content-Type', 'application/json');
    return new RequestOptions({headers: json_headers});
  }

  static handlePostResponse(res: Response) {
    return res;
  }

  static extractData(res: Response) {
    return res.json() || {};
  }

  static handleError(error: Response | any) {
    let errMsg: string;
    if (error instanceof Response) {
      const body = error.json() || '';
      const err = body.error || JSON.stringify(body);
      errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
    } else {
      errMsg = error.message ? error.message : error.toString();
    }
    (<any>window).fabric.sendNonFatalCrashWithStacktraceCreation(errMsg);
    return Observable.throw(errMsg);
  }

  static handleErrorWithoutParsing(error: Response | any) {
    return Observable.throw(error);
  }


}
<commit_msg>fail safe version of HandleError in rest_service because if the response has no body, it cannot be parsed to json and raise an error<commit_after>import {Injectable} from "@angular/core";
import {Observable} from "rxjs/Observable";
import {Headers, RequestOptions, Http, Response} from "@angular/http";
import {isNullOrUndefined} from "util";

@Injectable()
export class RestService {
  http: Http;
  protocol = 'http://';
  apiDomainName = 'localhost';
  apiPort = '3000';
  static headers: Headers;

  constructor(http: Http) {
    this.http = http;
  }

  /**
   * Return the URL of the REST API. It always ends with a '/'
   * @returns {string} example: localhost:3000/v1/
   */
  getBaseURL(): string {
    return this.protocol + this.apiDomainName + ':' + this.apiPort + '/';
  }

  /**
   * Return the base URL plus the given path
   * @param path a path (not starting with a '/')
   * @param parameters map of parameters
   * @returns {string}
   */
  getFullURL(path: String, parameters?: Map<String, String>): string {
    let fullURL = this.getBaseURL() + path;
    if (!isNullOrUndefined(parameters)) {
      fullURL += '?';
      parameters.forEach((value: String, key: String) => {
        fullURL += key + '=' + value + '&';
      });
    }
    return fullURL;
  }

  getHeaders(): RequestOptions {
    return new RequestOptions({headers: RestService.headers});
  }

  /**
   * Return a simple headers options for JSON content
   * @returns {Headers}
   */
  getHeadersForJSON(): RequestOptions {
    let json_headers = new Headers(RestService.headers);
    json_headers.append('Content-Type', 'application/json');
    return new RequestOptions({headers: json_headers});
  }

  static handlePostResponse(res: Response) {
    return res;
  }

  static extractData(res: Response) {
    return res.json() || {};
  }

  static handleError(error: Response | any) {
    try {
      let errMsg: string;
      if (error instanceof Response) {
        const body = error.json() || '';
        const err = body.error || JSON.stringify(body);
        errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
      } else {
        errMsg = error.message ? error.message : error.toString();
      }
      (<any>window).fabric.sendNonFatalCrashWithStacktraceCreation(errMsg);
      return Observable.throw(errMsg);
    } catch (e) {
      return Observable.throw(error);
    }
  }

  static handleErrorWithoutParsing(error: Response | any) {
    return Observable.throw(error);
  }


}

{'fraction_non_alphanumeric': 0.13920870839438979, 'fraction_numerical': 0.0037680552648105504, 'mean_word_length': 3.2508896797153026, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '4130226', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1429, 'n_words': 387}