handle thrown errors in updatePolicyMutation

merge-requests/3361/merge^2
Siddharth Singh 2025-04-12 03:17:50 +05:30
rodzic d93eb49e12
commit 554584bb82
Nie znaleziono w bazie danych klucza dla tego podpisu
1 zmienionych plików z 11 dodań i 1 usunięć

Wyświetl plik

@ -28,7 +28,17 @@ const useModerationPolicies = () => {
const updatePolicyMutation = useMutation({
mutationFn: async (spec: PolicySpec) => {
const response = await api.put('/api/v1/admin/ditto/policies/current', spec);
return response.json();
// Parse the JSON response
const data = await response.json();
// Check if the response contains an error
if (data && 'error' in data) {
// Throw the error to be caught by the caller
throw new Error(data.error);
}
return data;
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['admin', 'current_moderation_policy'] }); // Refetch after update