Skip to content
This repository was archived by the owner on Dec 23, 2025. It is now read-only.

Commit 3ea055e

Browse files
committed
fix: add error handler
1 parent 10a013e commit 3ea055e

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/services/cryptos.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import { CRYPTO_DATA_URL } from '@/lib/constants'
22
import { CryptoData } from '@/lib/types'
33

44
export async function getCryptoData(top = 100): Promise<CryptoData[]> {
5-
const response = await fetch(
6-
`${process.env.NEXT_PUBLIC_APP_URL}/api/cryptos?top=${top}`,
7-
)
8-
const data: CryptoData[] = await response.json()
5+
try {
6+
const response = await fetch(
7+
`${process.env.NEXT_PUBLIC_APP_URL}/api/cryptos?top=${top}`,
8+
)
9+
const data: CryptoData[] = await response.json()
910

10-
return data
11+
return data
12+
} catch (error) {
13+
console.error('Error fetching crypto data:', error)
14+
return []
15+
}
1116
}

0 commit comments

Comments
 (0)