@knime/utils 1.1.2 → 1.1.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @knime/utils
2
2
 
3
+ ## 1.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 9fa8163: bugfix/improvements in uploads: retry only on server error, reset placeholder skeleton on prepare upload error
8
+
3
9
  ## 1.1.2
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knime/utils",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Internal utility functions and constants shared across @knime packages.",
5
5
  "homepage": "https://knime.github.io/webapps-common/",
6
6
  "license": "GPL 3 and Additional Permissions according to Sec. 7 (SEE the file LICENSE)",
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable func-style */
2
2
  import sleep from "../sleep";
3
3
 
4
- const DEFAULT_RETRY_DELAY_MS = 0;
5
- const DEFAULT_RETRY_COUNT = 5;
4
+ export const DEFAULT_RETRY_DELAY_MS = 0;
5
+ export const DEFAULT_RETRY_COUNT = 5;
6
6
 
7
7
  /**
8
8
  * Helper to add retry capability to an async function
@@ -11,12 +11,17 @@ const DEFAULT_RETRY_COUNT = 5;
11
11
  * @param retryDelayMS delay in-between retries in millisecs. defaults to 0
12
12
  * @param excludeError predicate fn to exclude specific errors from causing a retry
13
13
  */
14
- export async function retryPromise<T>(
15
- fn: () => Promise<T>,
14
+ export async function retryPromise<T>({
15
+ fn,
16
16
  retryCount = DEFAULT_RETRY_COUNT,
17
17
  retryDelayMS = DEFAULT_RETRY_DELAY_MS,
18
- excludeError?: (error: Error) => boolean,
19
- ) {
18
+ excludeError,
19
+ }: {
20
+ fn: () => Promise<T>;
21
+ retryCount?: number;
22
+ retryDelayMS?: number;
23
+ excludeError?: (error: Error) => boolean;
24
+ }) {
20
25
  try {
21
26
  return await fn();
22
27
  } catch (error) {
@@ -28,7 +33,12 @@ export async function retryPromise<T>(
28
33
  await sleep(retryDelayMS);
29
34
 
30
35
  // eslint-disable-next-line no-return-await
31
- return await retryPromise(fn, retryCount - 1, retryDelayMS);
36
+ return await retryPromise({
37
+ fn,
38
+ retryCount: retryCount - 1,
39
+ retryDelayMS,
40
+ excludeError,
41
+ });
32
42
  }
33
43
 
34
44
  throw error;
@@ -261,11 +261,11 @@ export const createUploadManager = (config: UploaderManagerConfig) => {
261
261
  const chunk = file.slice(start, end);
262
262
 
263
263
  try {
264
- const { method, url } = await retryPromise(
265
- () => getUploadFilePartUrl(uploadId, chunkIndex + 1),
266
- DEFAULT_RETRY_COUNT,
267
- DEFAULT_RETRY_DELAY_MS,
268
- );
264
+ const { method, url } = await retryPromise({
265
+ fn: () => getUploadFilePartUrl(uploadId, chunkIndex + 1),
266
+ retryCount: DEFAULT_RETRY_COUNT,
267
+ retryDelayMS: DEFAULT_RETRY_DELAY_MS,
268
+ });
269
269
 
270
270
  consola.trace("File part upload url resolved", { method, url });
271
271
 
@@ -279,8 +279,8 @@ export const createUploadManager = (config: UploaderManagerConfig) => {
279
279
  };
280
280
 
281
281
  const filePartResponse = await runAbortablePromise(() =>
282
- retryPromise(
283
- () =>
282
+ retryPromise({
283
+ fn: () =>
284
284
  uploadChunkWithProgress({
285
285
  method,
286
286
  url,
@@ -289,9 +289,9 @@ export const createUploadManager = (config: UploaderManagerConfig) => {
289
289
  onProgress: onChunkUploadProgress,
290
290
  abortSignal: abortController.signal,
291
291
  }),
292
- DEFAULT_RETRY_COUNT,
293
- DEFAULT_RETRY_DELAY_MS,
294
- ),
292
+ retryCount: DEFAULT_RETRY_COUNT,
293
+ retryDelayMS: DEFAULT_RETRY_DELAY_MS,
294
+ }),
295
295
  );
296
296
 
297
297
  consola.trace(