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 () => {
150150 ) ;
151151
152152 try {
153+ const json = await res . json ( ) ;
154+
155+ if ( json . status && json . status . error_code ) {
156+ throw new Error ( "Rate limited" ) ;
157+ }
158+
153159 const {
154160 market_data : {
155161 market_cap : { usd : marketCap } ,
@@ -162,7 +168,7 @@ const getMarketCapStats = async () => {
162168 reddit_subscribers : redditSubscribers ,
163169 } ,
164170 developer_data : { stars : githubStars } ,
165- } = await res . json ( ) ;
171+ } = json ;
166172
167173 const cryptocurrency = {
168174 id,
@@ -223,21 +229,29 @@ const getMarketCapStats = async () => {
223229 console . log ( `Fetched ${ i } : ${ id } ` ) ;
224230 } catch ( err1 ) {
225231 console . log ( `Err Fetching ${ i } : ${ id } ` , err1 ) ;
226- Sentry . captureException ( err1 ) ;
227232 }
228233
229234 // CoinGecko rate limit is 10 calls per seconds
230235 if ( i && ! ( i % 10 ) ) {
231236 await sleep ( 15000 ) ;
232237 } else {
233- await sleep ( process . env . NODE_ENV === "production" ? 10_000 : 150 ) ;
238+ await sleep ( process . env . NODE_ENV === "production" ? 10000 : 150 ) ;
234239 }
235240 }
236241
237242 // Delete entries that are gone from the top 150
238243 await db . collection ( MARKET_CAP_STATS_COLLECTION ) . deleteMany ( {
239244 id : { $nin : ids } ,
240245 } ) ;
246+ } else {
247+ console . log (
248+ `Failed to get top ${ top } cryptocurrencies` ,
249+ cryptocurrencies ,
250+ ) ;
251+ await sleep ( 10000 ) ;
252+
253+ getMarketCapStats ( ) ;
254+ return ;
241255 }
242256
243257 const marketCapStats = await db
You can’t perform that action at this time.
0 commit comments