@pronto-tools-and-more/network-process 6.0.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/parts/ErrorCodes/ErrorCodes.js +1 -0
- package/src/parts/IsProcessingResourcesResponse/IsProcessingResourcesResponse.js +3 -0
- package/src/parts/ProcessingResourcesError/ProcessingResourcesError.js +8 -0
- package/src/parts/Timeout/Timeout.js +5 -0
- package/src/parts/UploadZip/UploadZip.js +32 -2
package/package.json
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
export const ProcessingResources = "E_PROCESSING_RESOURCES";
|
@@ -1,9 +1,12 @@
|
|
1
1
|
import { VError } from "@lvce-editor/verror";
|
2
|
-
import { openAsBlob } from "fs";
|
3
2
|
import ky from "ky";
|
3
|
+
import { openAsBlob } from "node:fs";
|
4
4
|
import * as Assert from "../Assert/Assert.js";
|
5
5
|
import * as GetFormData from "../GetFormData/GetFormData.js";
|
6
6
|
import * as GetXr from "../GetXr/GetXr.js";
|
7
|
+
import * as IsProcessingResourcesResponse from "../IsProcessingResourcesResponse/IsProcessingResourcesResponse.js";
|
8
|
+
import { ProcessingResourcesError } from "../ProcessingResourcesError/ProcessingResourcesError.js";
|
9
|
+
import * as Timeout from "../Timeout/Timeout.js";
|
7
10
|
|
8
11
|
const getHeaders = () => {
|
9
12
|
const xr = GetXr.getXr();
|
@@ -20,6 +23,8 @@ export const uploadZip = async ({
|
|
20
23
|
sessionId,
|
21
24
|
uploadTimeout,
|
22
25
|
message,
|
26
|
+
maxRetries = 10,
|
27
|
+
waitBetweenRetries = 60_000,
|
23
28
|
}) => {
|
24
29
|
try {
|
25
30
|
Assert.string(file);
|
@@ -46,7 +51,11 @@ export const uploadZip = async ({
|
|
46
51
|
},
|
47
52
|
timeout: uploadTimeout,
|
48
53
|
});
|
49
|
-
|
54
|
+
const text = await response.text();
|
55
|
+
if (IsProcessingResourcesResponse.isProcessingResourcesResponse(text)) {
|
56
|
+
throw new ProcessingResourcesError();
|
57
|
+
}
|
58
|
+
return text;
|
50
59
|
} catch (error) {
|
51
60
|
// @ts-ignore
|
52
61
|
if (error && error.name === "HTTPError") {
|
@@ -61,6 +70,27 @@ export const uploadZip = async ({
|
|
61
70
|
throw new Error(`Failed to upload zip file: Server ${serverMessage}`);
|
62
71
|
}
|
63
72
|
}
|
73
|
+
if (error && error instanceof ProcessingResourcesError) {
|
74
|
+
if (maxRetries > 0) {
|
75
|
+
console.info(
|
76
|
+
`[pronto-network-process] processing resources error, retrying ${maxRetries} more times in ${waitBetweenRetries}ms`
|
77
|
+
);
|
78
|
+
await Timeout.wait(waitBetweenRetries);
|
79
|
+
return uploadZip({
|
80
|
+
file,
|
81
|
+
uploadBaseUrl,
|
82
|
+
preview,
|
83
|
+
appId,
|
84
|
+
sessionId,
|
85
|
+
uploadTimeout,
|
86
|
+
message,
|
87
|
+
maxRetries: maxRetries - 1,
|
88
|
+
waitBetweenRetries,
|
89
|
+
});
|
90
|
+
} else {
|
91
|
+
throw new Error(`Failed to upload zip: Processing resources error`);
|
92
|
+
}
|
93
|
+
}
|
64
94
|
throw new VError(error, `Failed to upload zip`);
|
65
95
|
}
|
66
96
|
};
|