|
1 | 1 | import { commands, window } from "vscode"; |
2 | 2 | import { parse as parseYaml } from "yaml"; |
3 | 3 |
|
4 | | -import { getFirstMetadataValue } from "@api"; |
5 | | -import { Code, ConnectError } from "@connectrpc/connect"; |
6 | | -import { namespaces, vsCommands, SUPPORT_EMAIL } from "@constants"; |
| 4 | +import { ConnectError } from "@connectrpc/connect"; |
| 5 | +import { namespaces, vsCommands } from "@constants"; |
7 | 6 | import { getLocalResources } from "@controllers/utilities"; |
8 | 7 | import { translate } from "@i18n"; |
9 | 8 | import { LoggerService, ManifestService, ProjectsService } from "@services"; |
10 | | -import { getDirectoryOfFile, WorkspaceConfig } from "@utilities"; |
| 9 | +import { getDirectoryOfFile, WorkspaceConfig, handleConnectError } from "@utilities"; |
11 | 10 |
|
12 | 11 | export const applyManifest = async () => { |
13 | 12 | if (!window.activeTextEditor) { |
@@ -37,44 +36,11 @@ export const applyManifest = async () => { |
37 | 36 |
|
38 | 37 | if (createError) { |
39 | 38 | if (createError instanceof ConnectError) { |
40 | | - const errorType = getFirstMetadataValue(createError, "x-error-type"); |
41 | | - |
42 | | - if (createError.code === Code.AlreadyExists) { |
43 | | - // Project already exists, continue to apply manifest |
44 | | - } else if (errorType === "quota_limit_exceeded") { |
45 | | - const quotaLimit = getFirstMetadataValue(createError, "x-quota-limit"); |
46 | | - const quotaLimitUsed = getFirstMetadataValue(createError, "x-quota-used"); |
47 | | - const quotaLimitResource = getFirstMetadataValue(createError, "x-quota-resource"); |
48 | | - |
49 | | - commands.executeCommand( |
50 | | - vsCommands.showErrorMessage, |
51 | | - translate().t("errors.quotaLimitExceeded", { |
52 | | - limit: quotaLimit, |
53 | | - used: quotaLimitUsed, |
54 | | - resource: quotaLimitResource, |
55 | | - email: SUPPORT_EMAIL, |
56 | | - }) |
57 | | - ); |
58 | | - return; |
59 | | - } else if (errorType === "rate_limit_exceeded") { |
60 | | - commands.executeCommand(vsCommands.showErrorMessage, translate().t("errors.rateLimitExceeded")); |
61 | | - return; |
62 | | - } else if (createError.code === Code.ResourceExhausted) { |
63 | | - commands.executeCommand( |
64 | | - vsCommands.showErrorMessage, |
65 | | - translate().t("errors.resourceExhausted", { email: SUPPORT_EMAIL }) |
66 | | - ); |
67 | | - return; |
68 | | - } else if (createError.code === Code.Unauthenticated) { |
69 | | - commands.executeCommand(vsCommands.showErrorMessage, translate().t("errors.unauthenticated")); |
70 | | - return; |
71 | | - } else if (createError.code === Code.PermissionDenied) { |
72 | | - commands.executeCommand(vsCommands.showErrorMessage, translate().t("errors.permissionDenied")); |
73 | | - return; |
74 | | - } else { |
75 | | - commands.executeCommand(vsCommands.showErrorMessage, namespaces.applyManifest, createError.message); |
| 39 | + const shouldReturn = handleConnectError(createError, namespaces.applyManifest); |
| 40 | + if (shouldReturn) { |
76 | 41 | return; |
77 | 42 | } |
| 43 | + // If handleConnectError returns false, it means Code.AlreadyExists - continue to apply manifest |
78 | 44 | } else { |
79 | 45 | // Non-ConnectError |
80 | 46 | commands.executeCommand(vsCommands.showErrorMessage, namespaces.applyManifest, (createError as Error).message); |
|
0 commit comments