kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
handle thrown errors in updatePolicyMutation
rodzic
d93eb49e12
commit
554584bb82
|
@ -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
|
||||
|
|
Ładowanie…
Reference in New Issue