Caleb Fahlgren commited on
Commit
cd7a4df
·
1 Parent(s): c012cd9

add better error handling

Browse files
Files changed (1) hide show
  1. app/page.tsx +20 -9
app/page.tsx CHANGED
@@ -25,6 +25,7 @@ export default function IndexPage() {
25
  const [isLoading, setIsLoading] = useState(false)
26
  const [topFinetunedModels, setTopFinetunedModels] = useState<Array<{ model: string; finetunes: number }> | undefined>(undefined)
27
  const isMobile = useIsMobile()
 
28
 
29
  useEffect(() => {
30
  initDB()
@@ -72,16 +73,22 @@ export default function IndexPage() {
72
  }, [conn, isMobile])
73
 
74
  const fetchChartData = async (connection: duckdb.AsyncDuckDBConnection) => {
75
- const result = await connection.query(FETCH_CHART_DATA_QUERY)
 
76
 
77
- const data: ChartDataPoint[] = result.toArray().map((row) => ({
78
- month: new Date(row.month),
79
- models: Number(row.models),
80
- datasets: Number(row.datasets),
81
- spaces: Number(row.spaces),
82
- }))
83
 
84
- setChartData(data)
 
 
 
 
 
85
 
86
  const [modelLicenseResult, datasetLicenseResult, spaceSdkResult, topFinetunedModelsResult] =
87
  await Promise.all([
@@ -153,7 +160,11 @@ export default function IndexPage() {
153
  </h1>
154
 
155
  <div className="flex flex-col gap-4 max-w-6xl mt-10 w-full mx-auto">
156
- <AreaChartStacked data={chartData} />
 
 
 
 
157
  </div>
158
 
159
  {/* Mobile devices have much less resources to process these queries */}
 
25
  const [isLoading, setIsLoading] = useState(false)
26
  const [topFinetunedModels, setTopFinetunedModels] = useState<Array<{ model: string; finetunes: number }> | undefined>(undefined)
27
  const isMobile = useIsMobile()
28
+ const [chartDataError, setChartDataError] = useState<string | null>(null)
29
 
30
  useEffect(() => {
31
  initDB()
 
73
  }, [conn, isMobile])
74
 
75
  const fetchChartData = async (connection: duckdb.AsyncDuckDBConnection) => {
76
+ try {
77
+ const result = await connection.query(FETCH_CHART_DATA_QUERY)
78
 
79
+ const data: ChartDataPoint[] = result.toArray().map((row) => ({
80
+ month: new Date(row.month),
81
+ models: Number(row.models),
82
+ datasets: Number(row.datasets),
83
+ spaces: Number(row.spaces),
84
+ }))
85
 
86
+ setChartData(data)
87
+ setChartDataError(null)
88
+ } catch (error) {
89
+ console.error("Error fetching chart data:", error)
90
+ setChartDataError("There was an issue with the query for the Hugging Face Hub growth chart.")
91
+ }
92
 
93
  const [modelLicenseResult, datasetLicenseResult, spaceSdkResult, topFinetunedModelsResult] =
94
  await Promise.all([
 
160
  </h1>
161
 
162
  <div className="flex flex-col gap-4 max-w-6xl mt-10 w-full mx-auto">
163
+ {chartDataError ? (
164
+ <div className="text-center text-red-500">{chartDataError}</div>
165
+ ) : (
166
+ <AreaChartStacked data={chartData} />
167
+ )}
168
  </div>
169
 
170
  {/* Mobile devices have much less resources to process these queries */}