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

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js (-20 / +17 lines)
Lines 21-36 class HttpClient { Link Here
21
            ...options,
21
            ...options,
22
            headers: { ...this._headers, ...headers },
22
            headers: { ...this._headers, ...headers },
23
        })
23
        })
24
            .then(response => this.checkError(response, return_response))
24
            .then(response => {
25
            .then(
25
                if (!response.ok) {
26
                result => {
26
                    return response.text().then(text => {
27
                    res = result;
27
                        let json = JSON.parse(text);
28
                },
28
                        let message =
29
                err => {
29
                            json.error ||
30
                    error = err;
30
                            json.errors.map(e => e.message).join("\n") ||
31
                    setError(err.toString());
31
                            json;
32
                        console.log("Server returned an error:");
33
                        console.log(response);
34
                        throw new Error(message);
35
                    });
32
                }
36
                }
33
            )
37
                return return_response ? response : response.json();
38
            })
39
            .then(result => {
40
                res = result;
41
            })
34
            .catch(err => {
42
            .catch(err => {
35
                error = err;
43
                error = err;
36
                setError(err);
44
                setError(err);
Lines 143-158 class HttpClient { Link Here
143
            method: "PATCH",
151
            method: "PATCH",
144
        });
152
        });
145
    }
153
    }
146
147
    checkError(response, return_response = 0) {
148
        if (response.status >= 200 && response.status <= 299) {
149
            return return_response ? response : response.json();
150
        } else {
151
            console.log("Server returned an error:");
152
            console.log(response);
153
            throw Error("%s (%s)".format(response.statusText, response.status));
154
        }
155
    }
156
}
154
}
157
155
158
export default HttpClient;
156
export default HttpClient;
159
- 

Return to bug 34448