From 9fd0373e39ca67b542bb5a469dff27dc5953872b Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Thu, 6 Jun 2024 03:15:57 +0800 Subject: [PATCH] misc: improved error handling --- .../integration-sync-secret.ts | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/backend/src/services/integration-auth/integration-sync-secret.ts b/backend/src/services/integration-auth/integration-sync-secret.ts index d3731bd50..9d8ee8895 100644 --- a/backend/src/services/integration-auth/integration-sync-secret.ts +++ b/backend/src/services/integration-auth/integration-sync-secret.ts @@ -3394,32 +3394,40 @@ const syncSecretsRundeck = async ({ logger.info("No existing rundeck secrets"); } - for await (const [key, value] of Object.entries(secrets)) { - if (existingRundeckSecrets.includes(key)) { - await request.put(`${integration.url}/api/44/storage/${integration.path}/${key}`, value.value, { - headers: { - "X-Rundeck-Auth-Token": accessToken, - "Content-Type": "application/x-rundeck-data-password" - } - }); - } else { - await request.post(`${integration.url}/api/44/storage/${integration.path}/${key}`, value.value, { - headers: { - "X-Rundeck-Auth-Token": accessToken, - "Content-Type": "application/x-rundeck-data-password" - } - }); + try { + for await (const [key, value] of Object.entries(secrets)) { + if (existingRundeckSecrets.includes(key)) { + await request.put(`${integration.url}/api/44/storage/${integration.path}/${key}`, value.value, { + headers: { + "X-Rundeck-Auth-Token": accessToken, + "Content-Type": "application/x-rundeck-data-password" + } + }); + } else { + await request.post(`${integration.url}/api/44/storage/${integration.path}/${key}`, value.value, { + headers: { + "X-Rundeck-Auth-Token": accessToken, + "Content-Type": "application/x-rundeck-data-password" + } + }); + } } - } - for await (const existingSecret of existingRundeckSecrets) { - if (!(existingSecret in secrets)) { - await request.delete(`${integration.url}/api/44/storage/${integration.path}/${existingSecret}`, { - headers: { - "X-Rundeck-Auth-Token": accessToken - } - }); + for await (const existingSecret of existingRundeckSecrets) { + if (!(existingSecret in secrets)) { + await request.delete(`${integration.url}/api/44/storage/${integration.path}/${existingSecret}`, { + headers: { + "X-Rundeck-Auth-Token": accessToken + } + }); + } } + } catch (err: unknown) { + throw new Error( + `Ensure that the provided Rundeck URL is accessible by Infisical and that the linked API token has sufficient permissions.\n\n${ + (err as Error).message + }` + ); } };