@pronto-tools-and-more/network-process 6.9.0 → 6.10.1
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/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 +22 -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.1",
|
|
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
|
+
retryMessage: `[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
|
+
retryMessage: `[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,27 @@ 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
|
-
|
|
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, retryMessage } =
|
|
62
|
+
await HandleZipUploadError.handleZipUploadError({
|
|
63
|
+
error,
|
|
64
|
+
maxRetries,
|
|
65
|
+
waitBetweenRetries,
|
|
66
|
+
});
|
|
67
|
+
if (retry) {
|
|
68
|
+
console.info(retryMessage);
|
|
69
|
+
await Timeout.wait(waitBetweenRetries);
|
|
70
|
+
return uploadZip({
|
|
71
|
+
file,
|
|
72
|
+
uploadBaseUrl,
|
|
73
|
+
preview,
|
|
74
|
+
appId,
|
|
75
|
+
sessionId,
|
|
76
|
+
uploadTimeout,
|
|
77
|
+
message,
|
|
78
|
+
maxRetries: maxRetries - 1,
|
|
79
|
+
waitBetweenRetries,
|
|
80
|
+
});
|
|
93
81
|
}
|
|
94
|
-
throw new VError(
|
|
82
|
+
throw new VError(`Failed to upload zip: invalid state`);
|
|
95
83
|
}
|
|
96
84
|
};
|