|
Lines 1-4
Link Here
|
| 1 |
import { setError } from "../messages"; |
1 |
import { setError, isSubmitting, submitted } from "../messages"; |
| 2 |
|
2 |
|
| 3 |
class HttpClient { |
3 |
class HttpClient { |
| 4 |
constructor(options = {}) { |
4 |
constructor(options = {}) { |
|
Lines 12-20
class HttpClient {
Link Here
|
| 12 |
endpoint, |
12 |
endpoint, |
| 13 |
headers = {}, |
13 |
headers = {}, |
| 14 |
options = {}, |
14 |
options = {}, |
| 15 |
return_response = false |
15 |
return_response = false, |
|
|
16 |
mark_submitting = false, |
| 16 |
) { |
17 |
) { |
| 17 |
let res, error; |
18 |
let res, error; |
|
|
19 |
if ( mark_submitting) isSubmitting() |
| 18 |
await fetch(this._baseURL + endpoint, { |
20 |
await fetch(this._baseURL + endpoint, { |
| 19 |
...options, |
21 |
...options, |
| 20 |
headers: { ...this._headers, ...headers }, |
22 |
headers: { ...this._headers, ...headers }, |
|
Lines 32-38
class HttpClient {
Link Here
|
| 32 |
.catch((err) => { |
34 |
.catch((err) => { |
| 33 |
error = err; |
35 |
error = err; |
| 34 |
setError(err); |
36 |
setError(err); |
| 35 |
}); |
37 |
}).then(() => { |
|
|
38 |
if (mark_submitting) submitted()}) |
| 39 |
; |
| 36 |
|
40 |
|
| 37 |
if (error) throw Error(error); |
41 |
if (error) throw Error(error); |
| 38 |
|
42 |
|
|
Lines 51-57
class HttpClient {
Link Here
|
| 51 |
...params.options, |
55 |
...params.options, |
| 52 |
body: params.body ? JSON.stringify(params.body) : undefined, |
56 |
body: params.body ? JSON.stringify(params.body) : undefined, |
| 53 |
method: "POST", |
57 |
method: "POST", |
| 54 |
}); |
58 |
}, false, true); |
| 55 |
} |
59 |
} |
| 56 |
|
60 |
|
| 57 |
put(params = {}) { |
61 |
put(params = {}) { |
|
Lines 59-65
class HttpClient {
Link Here
|
| 59 |
...params.options, |
63 |
...params.options, |
| 60 |
body: params.body ? JSON.stringify(params.body) : undefined, |
64 |
body: params.body ? JSON.stringify(params.body) : undefined, |
| 61 |
method: "PUT", |
65 |
method: "PUT", |
| 62 |
}); |
66 |
}, false, true); |
| 63 |
} |
67 |
} |
| 64 |
|
68 |
|
| 65 |
delete(params = {}) { |
69 |
delete(params = {}) { |
|
Lines 67-73
class HttpClient {
Link Here
|
| 67 |
parseResponse: false, |
71 |
parseResponse: false, |
| 68 |
...params.options, |
72 |
...params.options, |
| 69 |
method: "DELETE", |
73 |
method: "DELETE", |
| 70 |
}, true); |
74 |
}, true, true); |
| 71 |
} |
75 |
} |
| 72 |
|
76 |
|
| 73 |
count(params = {}) { |
77 |
count(params = {}) { |
| 74 |
- |
|
|