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 56-62
class HttpClient {
Link Here
|
56 |
...params.options, |
60 |
...params.options, |
57 |
body, |
61 |
body, |
58 |
method: "POST", |
62 |
method: "POST", |
59 |
}); |
63 |
}, false, true); |
60 |
} |
64 |
} |
61 |
|
65 |
|
62 |
put(params = {}) { |
66 |
put(params = {}) { |
Lines 69-75
class HttpClient {
Link Here
|
69 |
...params.options, |
73 |
...params.options, |
70 |
body, |
74 |
body, |
71 |
method: "PUT", |
75 |
method: "PUT", |
72 |
}); |
76 |
}, false, true); |
73 |
} |
77 |
} |
74 |
|
78 |
|
75 |
delete(params = {}) { |
79 |
delete(params = {}) { |
Lines 81-87
class HttpClient {
Link Here
|
81 |
...params.options, |
85 |
...params.options, |
82 |
method: "DELETE", |
86 |
method: "DELETE", |
83 |
}, |
87 |
}, |
84 |
true |
88 |
true, true |
85 |
); |
89 |
); |
86 |
} |
90 |
} |
87 |
|
91 |
|
88 |
- |
|
|