Skip to content

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

add method to sanitize the error message

adilsone8409126e6a9
diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts
index 85e5b3b5a2..1e797c4967 100644
--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts
@@ -272,6 +272,36 @@ export const parseRotationErrorMessage = (err: unknown): string => {
: `${errorMessage.substring(0, MAX_MESSAGE_LENGTH - 3)}...`;
};
+export const getWebhookSanitizedErrorMessage = (err: unknown): string => {
+ let errorCategory = "an unknown error";
+
+ if (err instanceof AxiosError) {
+ const status = err?.response?.status;
+ if (status === 401 || status === 403) {
+ errorCategory = "an authentication/authorization error";
+ } else if (status === 404) {
+ errorCategory = "a not found error";
+ } else if (status === 429) {
+ errorCategory = "a rate limit error";
+ } else if (err.code === "ECONNREFUSED" || err.code === "ECONNRESET" || err.code === "ETIMEDOUT") {
+ errorCategory = "a connection error";
+ } else {
+ errorCategory = `an HTTP error (status ${status ?? "unknown"})`;
+ }
+ } else if (err instanceof Error) {
+ const msg = err.message.toLowerCase();
+ if (msg.includes("timeout") || msg.includes("etimedout")) {
+ errorCategory = "a timeout error";
+ } else if (msg.includes("econnrefused") || msg.includes("econnreset") || msg.includes("connect")) {
+ errorCategory = "a connection error";
+ } else if (msg.includes("authentication") || msg.includes("unauthorized") || msg.includes("permission")) {
+ errorCategory = "an authentication/authorization error";
+ }
+ }
+
+ return `Credential rotation failed due to ${errorCategory}. Check the rotation status in the dashboard for details.`;
+};
+
function haveUnequalProperties<T>(obj1: T, obj2: T, properties: (keyof T)[]): boolean {
return properties.some((prop) => obj1[prop] !== obj2[prop]);
}
diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts
index 1e765968e2..b2148c52d9 100644
--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts
+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-service.ts
@@ -25,6 +25,7 @@ import {
expandSecretRotation,
getNextUtcRotationInterval,
getSecretRotationRotateSecretJobOptions,
+ getWebhookSanitizedErrorMessage,
listSecretRotationOptions,
parseRotationErrorMessage,
throwOnImmutableParameterUpdate
@@ -1099,6 +1100,7 @@ export const secretRotationV2ServiceFactory = ({
return updatedRotation;
} catch (error) {
const errorMessage = parseRotationErrorMessage(error);
+ const webhookErrorMessage = getWebhookSanitizedErrorMessage(error);
let nextRetryTime: string | undefined;
if (!isManualRotation) {
@@ -1118,7 +1120,7 @@ export const secretRotationV2ServiceFactory = ({
secretPath: folder.path,
rotationName: secretRotation.name,
triggeredManually: isManualRotation,
- errorMessage,
+ errorMessage: webhookErrorMessage,
nextRetryTime
}
},