All files / publisher/hooks useCountryMetrics.ts

14.28% Statements 1/7
0% Branches 0/4
50% Functions 1/2
14.28% Lines 1/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      5x                                                
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`);
 
      if (!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;