<commit_before><commit_msg>feat(app): wrapped Http service with interceptors<commit_after>import {Injectable} from "@angular/core";
import {ConnectionBackend, Http, RequestOptions, RequestOptionsArgs, Response} from "@angular/http";
import {Observable} from "rxjs/Observable";

@Injectable()
export class CtHttp extends Http {

    private interceptorsAfter = [];

    private interceptorsBefore = [];

    private interceptorsError = [];

    constructor(backend: ConnectionBackend, defaultOptions: RequestOptions) {
        super(backend, defaultOptions);
    }

    get(url: string, options?: RequestOptionsArgs): Observable<Response> {

        this.interceptorsBefore.forEach((before) => before());

        return super.get(url, options).catch((error) => {

            this.interceptorsError.forEach((callback) => callback(error));

            return Observable.throw(error)

        }).do(() => this.interceptorsAfter.forEach((after) => after()))
    }

    post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {

        this.interceptorsBefore.forEach((callback) => callback());

        return super.post(url, body, options).catch((error) => {

            this.interceptorsError.forEach((callback) => callback(error));

            return Observable.throw(error)

        }).do(() => this.interceptorsAfter.forEach((callback) => callback()))
    }


    addBeforeInterceptor(callback: Function) {
        this.interceptorsBefore.push(callback);
    }

    removeBeforeInterceptor(callback: Function) {
        this.interceptorsBefore = this.interceptorsBefore.filter((interceptor) => interceptor !== callback)
    }

    addAfterInterceptor(callback: Function) {
        this.interceptorsAfter.push(callback);
    }

    removeAfterInterceptor(callback: Function) {
        this.interceptorsAfter = this.interceptorsAfter.filter((interceptor) => interceptor !== callback)
    }

    addErrorInterceptor(callback: Function) {
        this.interceptorsError.push(callback);
    }

    removeErrorInterceptor(callback: Function) {
        this.interceptorsError = this.interceptorsError.filter((interceptor) => interceptor !== callback)
    }
}
{'fraction_non_alphanumeric': 0.12832263978001834, 'fraction_numerical': 0.0, 'mean_word_length': 3.872767857142857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, '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': '5263446', 'n_tokens_mistral': 589, 'n_tokens_neox': 549, 'n_words': 103}