@pronto-tools-and-more/network-process 6.9.0 → 6.10.0
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +2 -2
- package/src/parts/CloudFront504Error/CloudFront504Error.js +8 -0
- package/src/parts/ErrorCodes/ErrorCodes.js +1 -0
- package/src/parts/HandleZipUploadError/HandleZipUploadError.js +43 -0
- package/src/parts/IsCloudFront504Error/IsCloudFront504Error.js +3 -0
- package/src/parts/ShouldRetryUpload/ShouldRetryUpload.js +12 -0
- package/src/parts/UploadZip/UploadZip.js +21 -34
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@pronto-tools-and-more/network-process",
|
3
|
-
"version": "6.
|
3
|
+
"version": "6.10.0",
|
4
4
|
"description": "",
|
5
5
|
"main": "src/networkProcessMain.js",
|
6
6
|
"type": "module",
|
@@ -15,7 +15,7 @@
|
|
15
15
|
"dependencies": {
|
16
16
|
"@lvce-editor/assert": "^1.3.0",
|
17
17
|
"@lvce-editor/ipc": "^11.0.1",
|
18
|
-
"@lvce-editor/json-rpc": "^4.
|
18
|
+
"@lvce-editor/json-rpc": "^4.1.0",
|
19
19
|
"@lvce-editor/verror": "^1.4.0",
|
20
20
|
"archiver": "^7.0.1",
|
21
21
|
"extract-zip": "^2.0.1",
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { VError } from "@lvce-editor/verror";
|
2
|
+
import * as IsCloudFront504Error from "../IsCloudFront504Error/IsCloudFront504Error.js";
|
3
|
+
import { ProcessingResourcesError } from "../ProcessingResourcesError/ProcessingResourcesError.js";
|
4
|
+
|
5
|
+
export const handleZipUploadError = async ({
|
6
|
+
error,
|
7
|
+
maxRetries,
|
8
|
+
waitBetweenRetries,
|
9
|
+
}) => {
|
10
|
+
if (error && error.name === "HTTPError") {
|
11
|
+
const serverMessage = await error.response.text();
|
12
|
+
if (IsCloudFront504Error.isCloudFront504Error(serverMessage)) {
|
13
|
+
if (maxRetries > 0) {
|
14
|
+
console.info();
|
15
|
+
return {
|
16
|
+
retry: true,
|
17
|
+
message: `[pronto-network-process] Cloudfront 504 error, retrying ${maxRetries} more times in ${waitBetweenRetries}ms`,
|
18
|
+
};
|
19
|
+
} else {
|
20
|
+
throw new Error(`Failed to upload zip: Cloudfront 504 error`);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
if (serverMessage === "INTERNAL_ERROR") {
|
24
|
+
throw new Error(
|
25
|
+
"Failed to list upload zip file: internal error. Hint: Check headers"
|
26
|
+
);
|
27
|
+
}
|
28
|
+
if (serverMessage) {
|
29
|
+
throw new Error(`Failed to upload zip file: Server ${serverMessage}`);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
if (error && error instanceof ProcessingResourcesError) {
|
33
|
+
if (maxRetries > 0) {
|
34
|
+
return {
|
35
|
+
retry: true,
|
36
|
+
message: `[pronto-network-process] processing resources error, retrying ${maxRetries} more times in ${waitBetweenRetries}ms`,
|
37
|
+
};
|
38
|
+
} else {
|
39
|
+
throw new Error(`Failed to upload zip: Processing resources error`);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
throw new VError(error, `Failed to upload zip`);
|
43
|
+
};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { CloudFront504Error } from "../CloudFront504Error/CloudFront504Error.js";
|
2
|
+
import { ProcessingResourcesError } from "../ProcessingResourcesError/ProcessingResourcesError.js";
|
3
|
+
|
4
|
+
export const shouldRetryUpload = (error) => {
|
5
|
+
if (error && error instanceof ProcessingResourcesError) {
|
6
|
+
return true;
|
7
|
+
}
|
8
|
+
if (error && error instanceof CloudFront504Error) {
|
9
|
+
return true;
|
10
|
+
}
|
11
|
+
return false;
|
12
|
+
};
|
@@ -4,6 +4,7 @@ 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 HandleZipUploadError from "../HandleZipUploadError/HandleZipUploadError.js";
|
7
8
|
import * as IsProcessingResourcesResponse from "../IsProcessingResourcesResponse/IsProcessingResourcesResponse.js";
|
8
9
|
import { ProcessingResourcesError } from "../ProcessingResourcesError/ProcessingResourcesError.js";
|
9
10
|
import * as Timeout from "../Timeout/Timeout.js";
|
@@ -57,40 +58,26 @@ export const uploadZip = async ({
|
|
57
58
|
}
|
58
59
|
return text;
|
59
60
|
} catch (error) {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
}
|
61
|
+
const { retry, message } = await HandleZipUploadError.handleZipUploadError({
|
62
|
+
error,
|
63
|
+
maxRetries,
|
64
|
+
waitBetweenRetries,
|
65
|
+
});
|
66
|
+
if (retry) {
|
67
|
+
console.info(message);
|
68
|
+
await Timeout.wait(waitBetweenRetries);
|
69
|
+
return uploadZip({
|
70
|
+
file,
|
71
|
+
uploadBaseUrl,
|
72
|
+
preview,
|
73
|
+
appId,
|
74
|
+
sessionId,
|
75
|
+
uploadTimeout,
|
76
|
+
message,
|
77
|
+
maxRetries: maxRetries - 1,
|
78
|
+
waitBetweenRetries,
|
79
|
+
});
|
93
80
|
}
|
94
|
-
throw new VError(
|
81
|
+
throw new VError(`Failed to upload zip: invalid state`);
|
95
82
|
}
|
96
83
|
};
|