@naturalcycles/js-lib 14.153.3 → 14.153.4

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.
@@ -8,6 +8,7 @@ const httpRequestError_1 = require("../error/httpRequestError");
8
8
  const number_util_1 = require("../number/number.util");
9
9
  const object_util_1 = require("../object/object.util");
10
10
  const pDelay_1 = require("../promise/pDelay");
11
+ const pTimeout_1 = require("../promise/pTimeout");
11
12
  const json_util_1 = require("../string/json.util");
12
13
  const stringifyAny_1 = require("../string/stringifyAny");
13
14
  const time_util_1 = require("../time/time.util");
@@ -119,7 +120,11 @@ class Fetcher {
119
120
  const abortController = new AbortController();
120
121
  req.init.signal = abortController.signal;
121
122
  timeout = setTimeout(() => {
122
- abortController.abort(`timeout of ${timeoutSeconds} sec`);
123
+ // Apparently, providing a `string` reason to abort() causes Undici to throw `invalid_argument` error,
124
+ // so, we're wrapping it in a TimeoutError instance
125
+ abortController.abort(new pTimeout_1.TimeoutError(`request timed out after ${timeoutSeconds} sec`));
126
+ // abortController.abort(`timeout of ${timeoutSeconds} sec`)
127
+ // abortController.abort()
123
128
  }, timeoutSeconds * 1000);
124
129
  }
125
130
  for (const hook of this.cfg.hooks.beforeRequest || []) {
@@ -246,7 +251,7 @@ class Fetcher {
246
251
  ]
247
252
  .filter(Boolean)
248
253
  .join(' '));
249
- if (this.cfg.logResponseBody) {
254
+ if (this.cfg.logResponseBody && res.body !== undefined) {
250
255
  logger.log(res.body);
251
256
  }
252
257
  }
@@ -5,6 +5,7 @@ import { HttpRequestError } from '../error/httpRequestError';
5
5
  import { _clamp } from '../number/number.util';
6
6
  import { _filterNullishValues, _filterUndefinedValues, _mapKeys, _merge, _omit, _pick, } from '../object/object.util';
7
7
  import { pDelay } from '../promise/pDelay';
8
+ import { TimeoutError } from '../promise/pTimeout';
8
9
  import { _jsonParse, _jsonParseIfPossible } from '../string/json.util';
9
10
  import { _stringifyAny } from '../string/stringifyAny';
10
11
  import { _since } from '../time/time.util';
@@ -104,7 +105,11 @@ export class Fetcher {
104
105
  const abortController = new AbortController();
105
106
  req.init.signal = abortController.signal;
106
107
  timeout = setTimeout(() => {
107
- abortController.abort(`timeout of ${timeoutSeconds} sec`);
108
+ // Apparently, providing a `string` reason to abort() causes Undici to throw `invalid_argument` error,
109
+ // so, we're wrapping it in a TimeoutError instance
110
+ abortController.abort(new TimeoutError(`request timed out after ${timeoutSeconds} sec`));
111
+ // abortController.abort(`timeout of ${timeoutSeconds} sec`)
112
+ // abortController.abort()
108
113
  }, timeoutSeconds * 1000);
109
114
  }
110
115
  for (const hook of this.cfg.hooks.beforeRequest || []) {
@@ -231,7 +236,7 @@ export class Fetcher {
231
236
  ]
232
237
  .filter(Boolean)
233
238
  .join(' '));
234
- if (this.cfg.logResponseBody) {
239
+ if (this.cfg.logResponseBody && res.body !== undefined) {
235
240
  logger.log(res.body);
236
241
  }
237
242
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.153.3",
3
+ "version": "14.153.4",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -14,6 +14,7 @@ import {
14
14
  _pick,
15
15
  } from '../object/object.util'
16
16
  import { pDelay } from '../promise/pDelay'
17
+ import { TimeoutError } from '../promise/pTimeout'
17
18
  import { _jsonParse, _jsonParseIfPossible } from '../string/json.util'
18
19
  import { _stringifyAny } from '../string/stringifyAny'
19
20
  import { _since } from '../time/time.util'
@@ -177,7 +178,11 @@ export class Fetcher {
177
178
  const abortController = new AbortController()
178
179
  req.init.signal = abortController.signal
179
180
  timeout = setTimeout(() => {
180
- abortController.abort(`timeout of ${timeoutSeconds} sec`)
181
+ // Apparently, providing a `string` reason to abort() causes Undici to throw `invalid_argument` error,
182
+ // so, we're wrapping it in a TimeoutError instance
183
+ abortController.abort(new TimeoutError(`request timed out after ${timeoutSeconds} sec`))
184
+ // abortController.abort(`timeout of ${timeoutSeconds} sec`)
185
+ // abortController.abort()
181
186
  }, timeoutSeconds * 1000) as any as number
182
187
  }
183
188
 
@@ -319,7 +324,7 @@ export class Fetcher {
319
324
  .join(' '),
320
325
  )
321
326
 
322
- if (this.cfg.logResponseBody) {
327
+ if (this.cfg.logResponseBody && res.body !== undefined) {
323
328
  logger.log(res.body)
324
329
  }
325
330
  }