diff --git a/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.test.ts b/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.test.ts index f773614388f..beb40742269 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.test.ts +++ b/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.test.ts @@ -304,4 +304,15 @@ describe("useUpdatePolicyVersionStatus", () => { "Failed to promote to production: Not found" ); }); + + it("throws when policyName is null", async () => { + const { result } = renderHook( + () => useUpdatePolicyVersionStatus(null), + { wrapper } + ); + + await expect( + result.current.mutateAsync({ policyId: "v2", status: "published" }) + ).rejects.toThrow("Missing access token or policy name"); + }); }); diff --git a/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.ts b/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.ts index 3eb55acafbe..9dc78180cdc 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.ts +++ b/ui/litellm-dashboard/src/app/(dashboard)/hooks/policies/usePolicyVersions.ts @@ -17,7 +17,7 @@ export const policyVersionKeys = createQueryKeys("policyVersions"); export interface PolicyVersionsResponse { policy_name: string; - versions: Policy[]; + versions: Policy[] | undefined; total_count: number; } @@ -95,8 +95,8 @@ export const useUpdatePolicyVersionStatus = ( { policyId: string; status: "published" | "production" } >({ mutationFn: async ({ policyId, status }) => { - if (!accessToken) { - throw new Error("Missing access token"); + if (!accessToken || !policyName) { + throw new Error("Missing access token or policy name"); } return await updatePolicyVersionStatus(accessToken, policyId, status); },