GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( a47fc9...3b0ef2 )
by Benjamin
43s
created

api.js ➔ ... ➔ ???   A

Complexity

Conditions 3
Paths 8

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
nc 8
dl 0
loc 23
rs 9.0856
c 2
b 0
f 2
cc 3
nop 1
1
export const Api = (config) => {
2
    const promise = new Promise((resolve) => {
3
4
        if (!config.method) {
5
            config.method = 'GET';
6
        }
7
8
        if (config.data) {
9
            config.data = JSON.stringify(config.data);
10
        }
11
12
        const request = new XMLHttpRequest();
0 ignored issues
show
Bug introduced by
The variable XMLHttpRequest seems to be never declared. If this is a global, consider adding a /** global: XMLHttpRequest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
13
14
        buildQueryString(config);
15
16
        request.open(config.method, config.route, true);
17
18
        setRequestHeaders(request, config);
19
20
        addAjaxEvents(request, config, resolve);
21
22
        request.send(config.data || null);
23
24
    });
25
26
    return promise;
27
};
28
29
export const setRequestHeaders = (request = {}, config = {}) => {
30
31
    if (!config.headers || !config.headers.contentType) {
32
        request.setRequestHeader(
33
            'Content-Type', 'application/x-www-form-urlencoded'
34
        );
35
    }
36
37
    if (!config.headers) {
38
        return false;
39
    }
40
41
    for (const key of Object.keys(config.headers)) {
42
        request.setRequestHeader(key, config.headers[key]);
43
    }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
44
};
45
46
export const addAjaxEvents = (request, config, resolver) => {
47
48
    const getResponse = () => {
49
        try {
50
            resolver(JSON.parse(request.responseText));
51
        }
52
53
        catch (e) {
54
            /* eslint-disable no-console */
55
            console.log(e);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
56
            /* eslint-enable no-console */
57
        }
58
    };
59
60
    request.addEventListener(
61
        'load', getResponse.bind(config.onSuccess, config.onSuccess)
62
    );
63
};
64
65
export const buildQueryString = (config = {}) => {
66
67
    const ret = {
68
        route: config.route + '?' + '_dc=' + Date.now() + '&'
69
    };
70
71
    if (!config.queryStringParams) {
72
        return ret;
73
    }
74
75
    for (const key of Object.keys(config.queryStringParams)) {
76
        if (config.queryStringParams[key]) {
77
            ret.route += key + '=' + config.queryStringParams[key] + '&';
78
        }
79
    }
80
81
    return ret;
82
};
83
84
export default Api;
85