@osimatic/helpers-js 1.0.111 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/http_client.js +19 -11
- package/package.json +1 -1
package/http_client.js
CHANGED
|
@@ -179,25 +179,33 @@ class HTTPClient {
|
|
|
179
179
|
static async request(method, url, data, successCallback, errorCallback, formErrorCallback) {
|
|
180
180
|
method = method.toUpperCase();
|
|
181
181
|
|
|
182
|
-
if (
|
|
182
|
+
if (!window.fetch) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
let body = null;
|
|
187
|
+
method = method.toUpperCase();
|
|
188
|
+
|
|
189
|
+
if ('POST' !== method && 'PATCH' !== method) {
|
|
183
190
|
url += (!url.includes('?') ? '?' : '') + HTTPClient.formatQueryString(data);
|
|
184
191
|
data = null;
|
|
185
192
|
}
|
|
186
193
|
|
|
187
|
-
if (
|
|
188
|
-
|
|
194
|
+
if (method === 'PATCH') {
|
|
195
|
+
HTTPClient.setHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
196
|
+
body = new URLSearchParams(HTTPClient.formatFormData(data)).toString();
|
|
189
197
|
}
|
|
190
198
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
method: method,
|
|
194
|
-
headers: HTTPClient.getHeaders(),
|
|
195
|
-
mode: 'cors',
|
|
196
|
-
cache: 'no-cache'
|
|
199
|
+
if ('POST' === method) {
|
|
200
|
+
body = HTTPClient.formatFormData(data);
|
|
197
201
|
}
|
|
198
202
|
|
|
199
|
-
|
|
200
|
-
|
|
203
|
+
const requestOptions = {
|
|
204
|
+
headers: HTTPClient.getHeaders(),
|
|
205
|
+
mode: 'cors',
|
|
206
|
+
cache: 'no-cache',
|
|
207
|
+
method,
|
|
208
|
+
body
|
|
201
209
|
}
|
|
202
210
|
|
|
203
211
|
const response = await fetch(url, requestOptions);
|