@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pronto-tools-and-more/network-process",
3
- "version": "6.9.0",
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.0.0",
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,8 @@
1
+ import * as ErrorCodes from "../ErrorCodes/ErrorCodes.js";
2
+
3
+ export class CloudFront504Error extends Error {
4
+ constructor() {
5
+ super("Cloudfront 504 Error");
6
+ this.code = ErrorCodes.CloudFront504;
7
+ }
8
+ }
@@ -1 +1,2 @@
1
1
  export const ProcessingResources = "E_PROCESSING_RESOURCES";
2
+ export const CloudFront504 = "E_CLOUDFRONT_504";
@@ -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,3 @@
1
+ export const isCloudFront504Error = (text) => {
2
+ return text.includes("<H1>504 ERROR</H1>");
3
+ };
@@ -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
- // @ts-ignore
61
- if (error && error.name === "HTTPError") {
62
- // @ts-ignore
63
- const serverMessage = await error.response.text();
64
- if (serverMessage === "INTERNAL_ERROR") {
65
- throw new Error(
66
- "Failed to list upload zip file: internal error. Hint: Check headers"
67
- );
68
- }
69
- if (serverMessage) {
70
- throw new Error(`Failed to upload zip file: Server ${serverMessage}`);
71
- }
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
- }
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(error, `Failed to upload zip`);
81
+ throw new VError(`Failed to upload zip: invalid state`);
95
82
  }
96
83
  };