@naturalcycles/js-lib 14.133.1 → 14.134.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.
@@ -42,6 +42,8 @@ export declare class Fetcher {
42
42
  /**
43
43
  * Default is yes,
44
44
  * unless there's reason not to (e.g method is POST).
45
+ *
46
+ * statusCode of 0 (or absense of it) will BE retried.
45
47
  */
46
48
  private shouldRetry;
47
49
  private getStatusFamily;
@@ -12,7 +12,7 @@ const time_util_1 = require("../time/time.util");
12
12
  const http_model_1 = require("./http.model");
13
13
  const defRetryOptions = {
14
14
  count: 2,
15
- timeout: 500,
15
+ timeout: 1000,
16
16
  timeoutMax: 30000,
17
17
  timeoutMultiplier: 2,
18
18
  };
@@ -253,11 +253,14 @@ class Fetcher {
253
253
  return;
254
254
  retryStatus.retryAttempt++;
255
255
  retryStatus.retryTimeout = (0, number_util_1._clamp)(retryStatus.retryTimeout * timeoutMultiplier, 0, timeoutMax);
256
- await (0, pDelay_1.pDelay)(retryStatus.retryTimeout);
256
+ const noise = Math.random() * 500;
257
+ await (0, pDelay_1.pDelay)(retryStatus.retryTimeout + noise);
257
258
  }
258
259
  /**
259
260
  * Default is yes,
260
261
  * unless there's reason not to (e.g method is POST).
262
+ *
263
+ * statusCode of 0 (or absense of it) will BE retried.
261
264
  */
262
265
  shouldRetry(res) {
263
266
  const { retryPost, retry4xx, retry5xx } = res.req;
@@ -81,6 +81,8 @@ function _stringifyAny(obj, opt = {}) {
81
81
  }
82
82
  if ((0, error_util_1._isErrorObject)(obj)) {
83
83
  if ((0, error_util_1._isHttpErrorObject)(obj)) {
84
+ // Only include (statusCode) if it's non-zero
85
+ // No: print (0), as it removes ambiguity
84
86
  // `replace` here works ONCE, exactly as we need it
85
87
  s = s.replace('HttpError', `HttpError(${obj.data.httpStatusCode})`);
86
88
  }
@@ -10,7 +10,7 @@ import { _since } from '../time/time.util';
10
10
  import { HTTP_METHODS } from './http.model';
11
11
  const defRetryOptions = {
12
12
  count: 2,
13
- timeout: 500,
13
+ timeout: 1000,
14
14
  timeoutMax: 30000,
15
15
  timeoutMultiplier: 2,
16
16
  };
@@ -291,11 +291,14 @@ export class Fetcher {
291
291
  return;
292
292
  retryStatus.retryAttempt++;
293
293
  retryStatus.retryTimeout = _clamp(retryStatus.retryTimeout * timeoutMultiplier, 0, timeoutMax);
294
- await pDelay(retryStatus.retryTimeout);
294
+ const noise = Math.random() * 500;
295
+ await pDelay(retryStatus.retryTimeout + noise);
295
296
  }
296
297
  /**
297
298
  * Default is yes,
298
299
  * unless there's reason not to (e.g method is POST).
300
+ *
301
+ * statusCode of 0 (or absense of it) will BE retried.
299
302
  */
300
303
  shouldRetry(res) {
301
304
  var _a;
@@ -77,6 +77,8 @@ export function _stringifyAny(obj, opt = {}) {
77
77
  }
78
78
  if (_isErrorObject(obj)) {
79
79
  if (_isHttpErrorObject(obj)) {
80
+ // Only include (statusCode) if it's non-zero
81
+ // No: print (0), as it removes ambiguity
80
82
  // `replace` here works ONCE, exactly as we need it
81
83
  s = s.replace('HttpError', `HttpError(${obj.data.httpStatusCode})`);
82
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.133.1",
3
+ "version": "14.134.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -30,7 +30,7 @@ import type { HttpStatusFamily } from './http.model'
30
30
 
31
31
  const defRetryOptions: FetcherRetryOptions = {
32
32
  count: 2,
33
- timeout: 500,
33
+ timeout: 1000,
34
34
  timeoutMax: 30_000,
35
35
  timeoutMultiplier: 2,
36
36
  }
@@ -336,12 +336,15 @@ export class Fetcher {
336
336
  retryStatus.retryAttempt++
337
337
  retryStatus.retryTimeout = _clamp(retryStatus.retryTimeout * timeoutMultiplier, 0, timeoutMax)
338
338
 
339
- await pDelay(retryStatus.retryTimeout)
339
+ const noise = Math.random() * 500
340
+ await pDelay(retryStatus.retryTimeout + noise)
340
341
  }
341
342
 
342
343
  /**
343
344
  * Default is yes,
344
345
  * unless there's reason not to (e.g method is POST).
346
+ *
347
+ * statusCode of 0 (or absense of it) will BE retried.
345
348
  */
346
349
  private shouldRetry(res: FetcherResponse): boolean {
347
350
  const { retryPost, retry4xx, retry5xx } = res.req
@@ -125,6 +125,8 @@ export function _stringifyAny(obj: any, opt: StringifyAnyOptions = {}): string {
125
125
 
126
126
  if (_isErrorObject(obj)) {
127
127
  if (_isHttpErrorObject(obj)) {
128
+ // Only include (statusCode) if it's non-zero
129
+ // No: print (0), as it removes ambiguity
128
130
  // `replace` here works ONCE, exactly as we need it
129
131
  s = s.replace('HttpError', `HttpError(${obj.data.httpStatusCode})`)
130
132
  }