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(" ") || |
31 |
setError(err.toString()); |
31 |
json; |
|
|
32 |
throw new Error(`${message}`); |
33 |
}); |
32 |
} |
34 |
} |
33 |
) |
35 |
return return_response ? response : response.json(); |
|
|
36 |
}) |
37 |
.then(result => { |
38 |
res = result; |
39 |
}) |
34 |
.catch(err => { |
40 |
.catch(err => { |
35 |
error = err; |
41 |
error = err; |
36 |
setError(err); |
42 |
setError(err); |
Lines 143-158
class HttpClient {
Link Here
|
143 |
method: "PATCH", |
149 |
method: "PATCH", |
144 |
}); |
150 |
}); |
145 |
} |
151 |
} |
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 |
} |
152 |
} |
157 |
|
153 |
|
158 |
export default HttpClient; |
154 |
export default HttpClient; |
159 |
- |
|
|