@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/helpers/api.js +18 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/services",
3
- "version": "2.18.1-6",
3
+ "version": "2.18.1-7",
4
4
  "description": "A collection of javascript functions/services to talk to veritree API",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -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
- return new Promise((resolve, reject) => {
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.json().then((json) => {
216
- response.ok ? resolve(json) : reject(json);
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