File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,12 @@ const getMarketCapStats = async () => {
150
150
) ;
151
151
152
152
try {
153
+ const json = await res . json ( ) ;
154
+
155
+ if ( json . status ?. error_code ) {
156
+ throw new Error ( "Rate limited" ) ;
157
+ }
158
+
153
159
const {
154
160
market_data : {
155
161
market_cap : { usd : marketCap } ,
@@ -162,7 +168,7 @@ const getMarketCapStats = async () => {
162
168
reddit_subscribers : redditSubscribers ,
163
169
} ,
164
170
developer_data : { stars : githubStars } ,
165
- } = await res . json ( ) ;
171
+ } = json ;
166
172
167
173
const cryptocurrency = {
168
174
id,
@@ -223,21 +229,29 @@ const getMarketCapStats = async () => {
223
229
console . log ( `Fetched ${ i } : ${ id } ` ) ;
224
230
} catch ( err1 ) {
225
231
console . log ( `Err Fetching ${ i } : ${ id } ` , err1 ) ;
226
- Sentry . captureException ( err1 ) ;
227
232
}
228
233
229
234
// CoinGecko rate limit is 10 calls per seconds
230
235
if ( i && ! ( i % 10 ) ) {
231
236
await sleep ( 15000 ) ;
232
237
} else {
233
- await sleep ( process . env . NODE_ENV === "production" ? 10_000 : 150 ) ;
238
+ await sleep ( process . env . NODE_ENV === "production" ? 10000 : 150 ) ;
234
239
}
235
240
}
236
241
237
242
// Delete entries that are gone from the top 150
238
243
await db . collection ( MARKET_CAP_STATS_COLLECTION ) . deleteMany ( {
239
244
id : { $nin : ids } ,
240
245
} ) ;
246
+ } else {
247
+ console . log (
248
+ `Failed to get top ${ top } cryptocurrencies` ,
249
+ cryptocurrencies ,
250
+ ) ;
251
+ await sleep ( 10000 ) ;
252
+
253
+ getMarketCapStats ( ) ;
254
+ return ;
241
255
}
242
256
243
257
const marketCapStats = await db
You can’t perform that action at this time.
0 commit comments