Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
check error type
Thiago Araujo da Silvaea0e5cf2b5bb
diff --git a/frontend/src/pages/pam/access-error.test.ts b/frontend/src/pages/pam/access-error.test.tsindex 9c80715df2..1fa3d8a106 100644--- a/frontend/src/pages/pam/access-error.test.ts+++ b/frontend/src/pages/pam/access-error.test.ts@@ -39,6 +39,13 @@ describe("getAccessErrorMessage", () => {expect(getAccessErrorMessage(error, FALLBACK)).toBe("Account requires approval");});+ test("returns the string message of a validation failure for an overlong value", () => {+ const message = "One or more field values exceed the maximum length allowed for this resource";+ const error = apiError(422, { error: "ValidationFailure", message });++ expect(getAccessErrorMessage(error, FALLBACK)).toBe(message);+ });+test.each([["a validation failure without issues",diff --git a/frontend/src/pages/pam/access-error.ts b/frontend/src/pages/pam/access-error.tsindex 22c7deb7ab..e18ce67401 100644--- a/frontend/src/pages/pam/access-error.ts+++ b/frontend/src/pages/pam/access-error.ts@@ -1,13 +1,16 @@import axios from "axios";-import { ApiErrorTypes, TApiErrors } from "@app/hooks/api/types";-export const getAccessErrorMessage = (error: unknown, fallback: string): string => {if (!axios.isAxiosError(error)) return fallback;- const data = error.response?.data as TApiErrors | undefined;- if (!data?.message) return fallback;- if (data.error === ApiErrorTypes.ValidationError) {- return data.message.map((issue) => issue.message).join(". ") || fallback;+ const message = (error.response?.data as { message?: unknown } | undefined)?.message;+ if (typeof message === "string") return message || fallback;+ if (Array.isArray(message)) {+ return (+ message+ .map((issue: { message?: unknown }) => issue?.message)+ .filter((text): text is string => typeof text === "string")+ .join(". ") || fallback+ );}- return typeof data.message === "string" ? data.message : fallback;+ return fallback;};