All files / publisher/hooks useCountryMetrics.ts

57.14% Statements 4/7
25% Branches 1/4
100% Functions 2/2
57.14% Lines 4/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28      19x     7x   7x                     7x                
import { useQuery } from "react-query";
 
function useCountryMetrics(snapId: string | undefined) {
  return useQuery({
    queryKey: ["countryMetrics", snapId],
    queryFn: async () => {
      const response = await fetch(`/${snapId}/metrics/country-metric`);
 
      Iif (!response.ok) {
        if (response.status === 404) {
          return {
            territories_total: 0,
            active_devices: {},
          };
        } else {
          throw new Error("Unable to fetch country metrics");
        }
      }
 
      return await response.json();
    },
    retry: 0,
    refetchOnWindowFocus: false,
  });
}
 
export default useCountryMetrics;