@pbvision/fastify-firestore-service 0.0.26 → 0.0.27

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/api/api.js +13 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pbvision/fastify-firestore-service",
3
- "version": "0.0.26",
3
+ "version": "0.0.27",
4
4
  "description": "Web Framework using Fastify and Firestore ORM",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/src/api/api.js CHANGED
@@ -341,7 +341,7 @@ class API {
341
341
  * @protected
342
342
  */
343
343
  async callAPI ({
344
- method = 'POST', headers = {}, url, body, qsParams
344
+ method = 'POST', headers = {}, url, body, qsParams, ignoreRespBody = false
345
345
  }) {
346
346
  headers = {
347
347
  ...headers,
@@ -366,17 +366,19 @@ class API {
366
366
  code: resp.status,
367
367
  isOk: resp.status >= 200 && resp.status <= 299
368
368
  }
369
- const respBody = await resp.text()
370
- if (respBody) {
371
- if (resp.headers.get('content-type')?.startsWith('application/json')) {
372
- try {
373
- ret.data = JSON.parse(respBody)
374
- } catch (e) {
375
- // istanbul ignore next
376
- throw new Error(`JSON.parse failed on ${respBody} with reason ${e}.`)
369
+ if (!ignoreRespBody) {
370
+ const respBody = await resp.text()
371
+ if (respBody) {
372
+ if (resp.headers.get('content-type')?.startsWith('application/json')) {
373
+ try {
374
+ ret.data = JSON.parse(respBody)
375
+ } catch (e) {
376
+ // istanbul ignore next
377
+ throw new Error(`JSON.parse failed on ${respBody} with reason ${e}.`)
378
+ }
379
+ } else {
380
+ ret.data = respBody
377
381
  }
378
- } else {
379
- ret.data = respBody
380
382
  }
381
383
  }
382
384
  return ret