@veritree/services 2.18.1-6 → 2.18.1-7
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/package.json +1 -1
- package/src/helpers/api.js +18 -4
package/package.json
CHANGED
package/src/helpers/api.js
CHANGED
|
@@ -206,15 +206,29 @@ export default class Api {
|
|
|
206
206
|
const config = getConfig(method, data, as);
|
|
207
207
|
const response = await fetch(url, config);
|
|
208
208
|
|
|
209
|
-
|
|
209
|
+
// console.log(response);
|
|
210
|
+
|
|
211
|
+
return new Promise(async (resolve, reject) => {
|
|
210
212
|
if (response.ok && response.status === 204) {
|
|
211
213
|
resolve();
|
|
212
214
|
return;
|
|
213
215
|
}
|
|
214
216
|
|
|
215
|
-
response.
|
|
216
|
-
|
|
217
|
-
|
|
217
|
+
const isJSON = response.headers.get('content-type').includes('json');
|
|
218
|
+
|
|
219
|
+
if(isJSON) {
|
|
220
|
+
response.json().then((json) => {
|
|
221
|
+
response.ok ? resolve(json) : reject(json);
|
|
222
|
+
});
|
|
223
|
+
} else {
|
|
224
|
+
const buff = await response.arrayBuffer().then(Buffer.from)
|
|
225
|
+
|
|
226
|
+
try {
|
|
227
|
+
resolve(buff.toString());
|
|
228
|
+
} catch (err) {
|
|
229
|
+
reject();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
218
232
|
});
|
|
219
233
|
}
|
|
220
234
|
|