mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
[Fix] UI - Policies: Fix unhandled promise rejections and isPending semantics
- Wrap mutateAsync calls in try/catch to swallow re-thrown errors (notifications already handled by onError in mutation hooks) - Use isLoading instead of isPending for version loading state — isPending is true when query is disabled with no cache, isLoading is only true during active fetches (matches original behavior) - Add isLoading assertions to disabled-state tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
79aea5ddcf
commit
8aa1ebfb07
2 changed files with 29 additions and 13 deletions
|
|
@ -96,6 +96,8 @@ describe("usePolicyVersions", () => {
|
|||
);
|
||||
|
||||
expect(result.current.fetchStatus).toBe("idle");
|
||||
// isLoading (not isPending) must be false when query is disabled
|
||||
expect(result.current.isLoading).toBe(false);
|
||||
expect(mockListPolicyVersions).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
|
@ -106,6 +108,8 @@ describe("usePolicyVersions", () => {
|
|||
);
|
||||
|
||||
expect(result.current.fetchStatus).toBe("idle");
|
||||
// isLoading (not isPending) must be false when query is disabled
|
||||
expect(result.current.isLoading).toBe(false);
|
||||
expect(mockListPolicyVersions).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1305,7 +1305,7 @@ export const FlowBuilderPage: React.FC<FlowBuilderPageProps> = ({
|
|||
|
||||
const {
|
||||
data: versionsData,
|
||||
isPending: isVersionsLoading,
|
||||
isLoading: isVersionsLoading,
|
||||
} = usePolicyVersions({
|
||||
policyName: editingPolicy?.policy_name,
|
||||
enabled: showVersionsSidebar,
|
||||
|
|
@ -1316,8 +1316,12 @@ export const FlowBuilderPage: React.FC<FlowBuilderPageProps> = ({
|
|||
const updateStatusMutation = useUpdatePolicyVersionStatus(editingPolicy?.policy_name);
|
||||
|
||||
const handleNewVersion = async () => {
|
||||
const newPolicy = await createVersionMutation.mutateAsync();
|
||||
onVersionCreated?.(newPolicy);
|
||||
try {
|
||||
const newPolicy = await createVersionMutation.mutateAsync();
|
||||
onVersionCreated?.(newPolicy);
|
||||
} catch {
|
||||
// Notification already shown by onError in the mutation hook
|
||||
}
|
||||
};
|
||||
|
||||
const handleSelectVersion = (policy: Policy) => {
|
||||
|
|
@ -1326,20 +1330,28 @@ export const FlowBuilderPage: React.FC<FlowBuilderPageProps> = ({
|
|||
|
||||
const handlePublishVersion = async () => {
|
||||
if (!editingPolicy?.policy_id) return;
|
||||
const updated = await updateStatusMutation.mutateAsync({
|
||||
policyId: editingPolicy.policy_id,
|
||||
status: "published",
|
||||
});
|
||||
onVersionStatusUpdated?.(updated);
|
||||
try {
|
||||
const updated = await updateStatusMutation.mutateAsync({
|
||||
policyId: editingPolicy.policy_id,
|
||||
status: "published",
|
||||
});
|
||||
onVersionStatusUpdated?.(updated);
|
||||
} catch {
|
||||
// Notification already shown by onError in the mutation hook
|
||||
}
|
||||
};
|
||||
|
||||
const handlePromoteToProduction = async () => {
|
||||
if (!editingPolicy?.policy_id) return;
|
||||
const updated = await updateStatusMutation.mutateAsync({
|
||||
policyId: editingPolicy.policy_id,
|
||||
status: "production",
|
||||
});
|
||||
onVersionStatusUpdated?.(updated);
|
||||
try {
|
||||
const updated = await updateStatusMutation.mutateAsync({
|
||||
policyId: editingPolicy.policy_id,
|
||||
status: "production",
|
||||
});
|
||||
onVersionStatusUpdated?.(updated);
|
||||
} catch {
|
||||
// Notification already shown by onError in the mutation hook
|
||||
}
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue