Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

add better error message

Matheus Nogueira11bca40f42d2
diff --git a/backend/src/services/secret-sync/cloudflare-workers/cloudflare-workers-fns.ts b/backend/src/services/secret-sync/cloudflare-workers/cloudflare-workers-fns.ts
index 98c9869f0a..cf9404cfec 100644
--- a/backend/src/services/secret-sync/cloudflare-workers/cloudflare-workers-fns.ts
+++ b/backend/src/services/secret-sync/cloudflare-workers/cloudflare-workers-fns.ts
@@ -1,6 +1,9 @@
+import { AxiosError } from "axios";
+
import { request } from "@app/lib/config/request";
import { applyJitter } from "@app/lib/dates";
import { delay as delayMs } from "@app/lib/delay";
+import { BadRequestError } from "@app/lib/errors";
import { IntegrationUrls } from "@app/services/integration-auth/integration-list";
import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";
import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";
@@ -8,6 +11,28 @@ import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";
import { SECRET_SYNC_NAME_MAP } from "../secret-sync-maps";
import { TCloudflareWorkersSyncWithCredentials } from "./cloudflare-workers-types";
+const CLOUDFLARE_UNDEPLOYED_VERSION_ERROR_CODE = 10215;
+
+type TCloudflareErrorResponse = {
+ errors?: Array<{ code: number; message: string }>;
+};
+
+const throwOnUndeployedVersionError = (err: unknown) => {
+ if (
+ err instanceof AxiosError &&
+ (err.response?.data as TCloudflareErrorResponse)?.errors?.some(
+ (e) => e.code === CLOUDFLARE_UNDEPLOYED_VERSION_ERROR_CODE
+ )
+ ) {
+ throw new BadRequestError({
+ message:
+ "Cloudflare rejected the secret update because the latest Worker version is not deployed; deploy the latest Worker version, then retry the secret sync."
+ });
+ }
+
+ throw err;
+};
+
const getSecretKeys = async (secretSync: TCloudflareWorkersSyncWithCredentials): Promise<string[]> => {
const {
destinationConfig,
@@ -43,18 +68,22 @@ export const CloudflareWorkersSyncFns = {
const existingSecretNames = await getSecretKeys(secretSync);
const secretMapKeys = new Set(Object.keys(secretMap));
- for await (const [key, val] of Object.entries(secretMap)) {
- await delayMs(Math.max(0, applyJitter(100, 200)));
- await request.put(
- `${IntegrationUrls.CLOUDFLARE_WORKERS_API_URL}/client/v4/accounts/${accountId}/workers/scripts/${scriptId}/secrets`,
- { name: key, text: val.value, type: "secret_text" },
- {
- headers: {
- Authorization: `Bearer ${apiToken}`,
- "Content-Type": "application/json"
+ try {
+ for await (const [key, val] of Object.entries(secretMap)) {
+ await delayMs(Math.max(0, applyJitter(100, 200)));
+ await request.put(
+ `${IntegrationUrls.CLOUDFLARE_WORKERS_API_URL}/client/v4/accounts/${accountId}/workers/scripts/${scriptId}/secrets`,
+ { name: key, text: val.value, type: "secret_text" },
+ {
+ headers: {
+ Authorization: `Bearer ${apiToken}`,
+ "Content-Type": "application/json"
+ }
}
- }
- );
+ );
+ }
+ } catch (err) {
+ throwOnUndeployedVersionError(err);
}
if (!secretSync.syncOptions.disableSecretDeletion) {