fix handleResponse function

admin-dashboard-policy-ui
Siddharth Singh 2025-05-07 09:51:21 +05:30
rodzic b5e142fb79
commit 5ed2edb125
Nie znaleziono w bazie danych klucza dla tego podpisu
1 zmienionych plików z 7 dodań i 3 usunięć

Wyświetl plik

@ -9,15 +9,19 @@ const useModerationPolicies = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const handleResponse = async (response: MastodonResponse, message: string) => { const handleResponse = async (response: MastodonResponse, message: string) => {
const details = await response.error() if (!response.ok) {
.then(v => v?.error || 'Unknown error'); const details = await response.error()
if (!response.ok) throw new Error(`${message}: ${details}`); .then(v => v?.error || 'Unknown error');
throw new Error(`${message}: ${details}`);
}
const data = await response.json(); const data = await response.json();
// Check if the response contains an error // Check if the response contains an error
if (data && 'error' in data) throw new Error(data.error); if (data && 'error' in data) throw new Error(data.error);
return data; return data;
}; };
const allPoliciesQuery = useQuery({ const allPoliciesQuery = useQuery({
queryKey: ['admin', 'moderation_policies'], queryKey: ['admin', 'moderation_policies'],
queryFn: async () => { queryFn: async () => {