View | Details | Raw Unified | Return to bug 32939
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js (-5 / +22 lines)
Lines 8-20 class HttpClient { Link Here
8
        };
8
        };
9
    }
9
    }
10
10
11
    async _fetchJSON(endpoint, headers = {}, options = {}) {
11
    async _fetchJSON(
12
        endpoint,
13
        headers = {},
14
        options = {},
15
        return_response = false
16
    ) {
12
        let res;
17
        let res;
13
        await fetch(this._baseURL + endpoint, {
18
        await fetch(this._baseURL + endpoint, {
14
            ...options,
19
            ...options,
15
            headers: { ...this._headers, ...headers },
20
            headers: { ...this._headers, ...headers },
16
        })
21
        })
17
            .then(this.checkError)
22
            .then((response) => this.checkError(response, return_response))
18
            .then(
23
            .then(
19
                (result) => {
24
                (result) => {
20
                    res = result;
25
                    res = result;
Lines 60-65 class HttpClient { Link Here
60
        });
65
        });
61
    }
66
    }
62
67
68
    count(params = {}) {
69
        let res;
70
        this._fetchJSON(params.endpoint, params.headers, 1).then(
71
            (response) => {
72
                if (response) {
73
                    res = response.headers.get("X-Total-Count");
74
                }
75
            },
76
            (error) => {
77
                setError(error.toString());
78
            }
79
        );
80
        return res;
81
    }
82
63
    checkError(response, return_response = 0) {
83
    checkError(response, return_response = 0) {
64
        if (response.status >= 200 && response.status <= 299) {
84
        if (response.status >= 200 && response.status <= 299) {
65
            return return_response ? response : response.json();
85
            return return_response ? response : response.json();
Lines 69-76 class HttpClient { Link Here
69
            throw Error("%s (%s)".format(response.statusText, response.status));
89
            throw Error("%s (%s)".format(response.statusText, response.status));
70
        }
90
        }
71
    }
91
    }
72
73
    //TODO: Implement count method
74
}
92
}
75
93
76
export default HttpClient;
94
export default HttpClient;
77
- 

Return to bug 32939