<commit_before>import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { Observable }       from 'rxjs/Observable';
import { Observer }       from 'rxjs/Observer';
import { BehaviorSubject }       from 'rxjs/BehaviorSubject';
import { Subject }          from 'rxjs/Subject';

import { ApiErrorHandle } from '../api-error-handle';

@Injectable()
export class ApiErrorService {

  // private properties
  private errorSource: Subject<ApiErrorHandle> = new Subject<ApiErrorHandle>();

  // public methods
  getObservable(): Observable<ApiErrorHandle> {
    return this.errorSource.asObservable();
  }

  handleError(o: Observable<Response>, dismissFn?: () => any): Observable<Response> {
    let s = new BehaviorSubject<Response>(null);
    this.subscribe(o, s, dismissFn);
    return s.asObservable();
  };

  // private methods
  private subscribe(o: Observable<Response>, s: BehaviorSubject<Response>, dismissFn?: () => any): void {
    o.subscribe(
      (res: Response) => {
        s.next(res);
        s.complete();
      },
      (error: any) => {
        console.error('An error occurred', error); // for demo purposes only
        let json = error.json()
        let errMsg = json && json['message'] ? json['message']
                   : error.message ? error.message
                   : error.status ? `API error: ${error.status} - ${error.statusText}`
                   : 'API error';
        let retryFn: () => void = function() {
          this.subscribe(o, s, dismissFn);
          return;
        };
        this.errorSource.next(new ApiErrorHandle(errMsg, s, dismissFn, retryFn) );<commit_msg>Bugfix<commit_after>import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { Observable }       from 'rxjs/Observable';
import { Observer }       from 'rxjs/Observer';
import { BehaviorSubject }       from 'rxjs/BehaviorSubject';
import { Subject }          from 'rxjs/Subject';

import { ApiErrorHandle } from '../api-error-handle';

@Injectable()
export class ApiErrorService {

  // private properties
  private errorSource: Subject<ApiErrorHandle> = new Subject<ApiErrorHandle>();

  // public methods
  getObservable(): Observable<ApiErrorHandle> {
    return this.errorSource.asObservable();
  }

  handleError(o: Observable<Response>, dismissFn?: () => any): Observable<Response> {
    let s = new BehaviorSubject<Response>(null);
    this.subscribe(o, s, dismissFn);
    return s.asObservable();
  };

  // private methods
  private subscribe(o: Observable<Response>, s: BehaviorSubject<Response>, dismissFn?: () => any): void {
    o.subscribe(
      (res: Response) => s.next(res),
      (error: any) => {
        console.error('An error occurred', error); // for demo purposes only
        let json = error.json()
        let errMsg = json && json['message'] ? json['message']
                   : error.message ? error.message
                   : error.status ? `API error: ${error.status} - ${error.statusText}`
                   : 'API error';
        let retryFn: () => void = function() {
          this.subscribe(o, s, dismissFn);
          return;
        };
        this.errorSource.next(new ApiErrorHandle(errMsg, s, dismissFn, retryFn) );
{'fraction_non_alphanumeric': 0.14202094886013555, 'fraction_numerical': 0.0, 'mean_word_length': 2.879330943847073, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 29, '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': '250055', 'n_tokens_mistral': 913, 'n_tokens_neox': 897, 'n_words': 227}