{"record":{"id":"5bc705195fe510e7","repo":"QuantumNous/new-api","slug":"failed-to-fetch-checkin-status","errorCode":null,"errorMessage":"Failed to fetch checkin status","messagePattern":"Failed to fetch checkin status","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web/src/features/profile/components/checkin-calendar-card.tsx","lineNumber":92,"sourceCode":"    const y = currentMonth.getFullYear()\n    const m = String(currentMonth.getMonth() + 1).padStart(2, '0')\n    return `${y}-${m}`\n  }, [currentMonth])\n\n  // Fetch checkin status\n  /* eslint-disable @tanstack/query/exhaustive-deps */\n  const {\n    data: checkinData,\n    isLoading,\n    refetch,\n  } = useQuery({\n    queryKey: ['checkin-status', currentMonthStr],\n    queryFn: async () => {\n      const res = await getCheckinStatus(currentMonthStr)\n      if (res.success && res.data) {\n        return res.data\n      }\n      throw new Error(res.message || t('Failed to fetch checkin status'))\n    },\n    enabled: checkinEnabled,\n    staleTime: 30000,\n  })\n  /* eslint-enable @tanstack/query/exhaustive-deps */\n\n  const checkinRecordsMap = useMemo(() => {\n    const map: Record<string, number> = {}\n    const records = checkinData?.stats?.records || []\n    records.forEach((record: CheckinRecord) => {\n      map[record.checkin_date] = record.quota_awarded\n    })\n    return map\n  }, [checkinData?.stats?.records])\n\n  const monthlyQuota = useMemo(() => {\n    const records = checkinData?.stats?.records || []\n    return records.reduce(","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/QuantumNous/new-api/blob/e2c7aa7b102c2075eae2377df3508658d45e88dc/web/src/features/profile/components/checkin-calendar-card.tsx#L74-L110","documentation":"Thrown inside the react-query queryFn of the checkin calendar card when getCheckinStatus(currentMonthStr) resolves with success=false or missing data. The query runs only when checkinEnabled, keyed by month string, with a 30s staleTime; the thrown message feeds react-query's error state.","triggerScenarios":"Mounting the profile page with check-in enabled while the backend reports failure for the month status (check-in feature misconfigured, invalid month param) or the request rejects (401 session, network).","commonSituations":"Check-in feature flag half-enabled server-side; user session expired so /api/user/checkin returns 401; month string computed at midnight boundary mismatching backend expectations; backend deploy missing the checkin route.","solutions":["Confirm the check-in feature is fully enabled in system settings (server side), not just the client flag","Refresh/re-login to rule out session expiry, then let react-query refetch","Call the checkin status endpoint with the same month parameter and read the message field","Check backend logs for the checkin route at request time (route missing vs internal error)"],"exampleFix":"// before\nconst res = await getCheckinStatus(currentMonthStr)\nif (res.success && res.data) {\n  return res.data\n}\nthrow new Error(res.message || t('Failed to fetch checkin status'))\n// after - add a retry for transient failures\nconst res = await getCheckinStatus(currentMonthStr)\nif (res.success && res.data) {\n  return res.data\n}\nthrow new Error(res.message || t('Failed to fetch checkin status'))\n// queryClient option: { retry: 1, refetchOnWindowFocus: false }","handlingStrategy":"try-catch","validationCode":"const isValidMonth = /^\\d{4}-\\d{2}$/.test(currentMonthStr)\n// build query with enabled: checkinEnabled && isValidMonth","typeGuard":null,"tryCatchPattern":"// inside queryFn\nconst res = await getCheckinStatus(currentMonthStr)\nif (res.success && res.data) return res.data\nthrow new Error(res.message || t('Failed to fetch checkin status'))\n// consumers read { data, isLoading, error } from useQuery","preventionTips":["Gate the query on both checkinEnabled and a valid month format","Give the query a bounded retry (1) for transient backend blips","Render react-query's error state in the card instead of swallowing it"],"tags":["api-error","checkin","react-query","profile","i18n"],"backgroundTag":null,"analyzedSha":"e2c7aa7b102c2075eae2377df3508658d45e88dc","analyzedAt":"2026-08-15T10:35:18.111Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}