<commit_before>import request from 'superagent';
import loginStore from '../stores/login.store';
import { BASE_URL, GET_METHOD, POST_METHOD, PUT_METHOD, DELETE_METHOD } from '../constants/api.constants';
import loginActions from '../actions/login.action.js';

export default class {
    constructor(baseUrl) {
        this._baseUrl = `${BASE_URL}${baseUrl}`;
    }

    get() {
        return this._request(GET_METHOD, this._baseUrl);
    }

    post(data) {
        return this._request(POST_METHOD, this._baseUrl, data);
    }

    put(data, id) {
        let url = this._baseUrl;

        if (id) {
            url += `/${id}`;
        }

        return this._request(PUT_METHOD, url, data);
    }

    delete(id) {
        return this._request(DELETE_METHOD, `${this._baseUrl}/${id}`);
    }

    _request(method, url, data) {
        const req = request(method, url);

        if (loginStore.isLoggedIn) {
            req.set('Authorization', `Bearer ${loginStore.jwt}`);
        }

        if (data) {
            req.send(data);
        }

        return new Promise((resolve, reject) => {
            req.end((err, response) => {
                if (err) {
                    if (response.status === 401) {
                        loginActions.logoutUser();
                    }

                    return reject(response.statusText);
                }

                return resolve(JSON.parse(response.text));
            });
        });
    }
}
<commit_msg>return json body if it has parsed otherwise return the raw text<commit_after>import request from 'superagent';
import loginStore from '../stores/login.store';
import { BASE_URL, GET_METHOD, POST_METHOD, PUT_METHOD, DELETE_METHOD } from '../constants/api.constants';
import loginActions from '../actions/login.action.js';

export default class {
    constructor(baseUrl) {
        this._baseUrl = `${BASE_URL}${baseUrl}`;
    }

    get() {
        return this._request(GET_METHOD, this._baseUrl);
    }

    post(data) {
        return this._request(POST_METHOD, this._baseUrl, data);
    }

    put(data, id) {
        let url = this._baseUrl;

        if (id) {
            url += `/${id}`;
        }

        return this._request(PUT_METHOD, url, data);
    }

    delete(id) {
        return this._request(DELETE_METHOD, `${this._baseUrl}/${id}`);
    }

    _request(method, url, data) {
        const req = request(method, url);

        if (loginStore.isLoggedIn) {
            req.set('Authorization', `Bearer ${loginStore.jwt}`);
        }

        if (data) {
            req.send(data);
        }

        return new Promise((resolve, reject) => {
            req.end((err, response) => {
                if (err) {
                    if (response.status === 401) {
                        loginActions.logoutUser();
                    }

                    return reject(response.statusText);
                }

                return resolve(response.body ? response.body : response.text);
            });
        });
    }
}

{'fraction_non_alphanumeric': 0.13702720637027208, 'fraction_numerical': 0.0019907100199071004, 'mean_word_length': 1.799442896935933, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7211614', 'n_tokens_mistral': 898, 'n_tokens_neox': 869, 'n_words': 179}