@@ -19,6 +19,7 @@ import {
19
19
CONTENT_TRANSLATED_ROOT ,
20
20
CONTRIBUTOR_SPOTLIGHT_ROOT ,
21
21
BUILD_OUT_ROOT ,
22
+ DEV_MODE ,
22
23
} from "../libs/env/index.js" ;
23
24
import { isValidLocale } from "../libs/locale-utils/index.js" ;
24
25
import { DocFrontmatter , NewsItem } from "../libs/types/document.js" ;
@@ -368,14 +369,25 @@ async function fetchGitHubPRs(repo, count = 5) {
368
369
"sort:updated" ,
369
370
] . join ( "+" ) ;
370
371
const pullRequestUrl = `https://api.github.com/search/issues?q=${ pullRequestsQuery } &per_page=${ count } ` ;
371
- const pullRequestsData = ( await got ( pullRequestUrl ) . json ( ) ) as {
372
- items : any [ ] ;
373
- } ;
374
- const prDataRepo = pullRequestsData . items . map ( ( item ) => ( {
375
- ...item ,
376
- repo : { name : repo , url : `https://github.com/${ repo } ` } ,
377
- } ) ) ;
378
- return prDataRepo ;
372
+ try {
373
+ const pullRequestsData = ( await got ( pullRequestUrl ) . json ( ) ) as {
374
+ items : any [ ] ;
375
+ } ;
376
+ const prDataRepo = pullRequestsData . items . map ( ( item ) => ( {
377
+ ...item ,
378
+ repo : { name : repo , url : `https://github.com/${ repo } ` } ,
379
+ } ) ) ;
380
+ return prDataRepo ;
381
+ } catch ( e ) {
382
+ const msg = `Couldn't fetch recent GitHub contributions for repo ${ repo } !` ;
383
+ if ( ! DEV_MODE ) {
384
+ console . error ( `Error: ${ msg } ` ) ;
385
+ throw e ;
386
+ }
387
+
388
+ console . warn ( `Warning: ${ msg } ` ) ;
389
+ return [ ] ;
390
+ }
379
391
}
380
392
381
393
async function fetchRecentContributions ( ) {
@@ -403,10 +415,6 @@ async function fetchRecentContributions() {
403
415
}
404
416
405
417
async function fetchLatestNews ( ) {
406
- const xml = await got ( "https://hacks.mozilla.org/category/mdn/feed/" ) . text ( ) ;
407
-
408
- const $ = cheerio . load ( xml , { xmlMode : true } ) ;
409
-
410
418
const items : NewsItem [ ] = [ ] ;
411
419
412
420
items . push (
@@ -449,25 +457,48 @@ async function fetchLatestNews() {
449
457
name : "developer.mozilla.org" ,
450
458
url : `/${ DEFAULT_LOCALE } /blog/` ,
451
459
} ,
452
- }
460
+ } ,
461
+ ...( await fetchHacksNews ( ) )
453
462
) ;
454
463
455
- $ ( "item" ) . each ( ( i , item ) => {
456
- const $item = $ ( item ) ;
457
-
458
- items . push ( {
459
- title : $item . find ( "title" ) . text ( ) ,
460
- url : $item . find ( "guid" ) . text ( ) ,
461
- author : $item . find ( "dc\\:creator" ) . text ( ) ,
462
- published_at : $item . find ( "pubDate" ) . text ( ) ,
463
- source : {
464
- name : "hacks.mozilla.org" ,
465
- url : "https://hacks.mozilla.org/category/mdn/" ,
466
- } ,
467
- } ) ;
468
- } ) ;
469
-
470
464
return {
471
465
items,
472
466
} ;
473
467
}
468
+
469
+ async function fetchHacksNews ( ) : Promise < NewsItem [ ] > {
470
+ try {
471
+ const xml = await got (
472
+ "https://hacks.mozilla.org/category/mdn/feed/"
473
+ ) . text ( ) ;
474
+
475
+ const $ = cheerio . load ( xml , { xmlMode : true } ) ;
476
+
477
+ const items : NewsItem [ ] = [ ] ;
478
+ $ ( "item" ) . each ( ( i , item ) => {
479
+ const $item = $ ( item ) ;
480
+
481
+ items . push ( {
482
+ title : $item . find ( "title" ) . text ( ) ,
483
+ url : $item . find ( "guid" ) . text ( ) ,
484
+ author : $item . find ( "dc\\:creator" ) . text ( ) ,
485
+ published_at : $item . find ( "pubDate" ) . text ( ) ,
486
+ source : {
487
+ name : "hacks.mozilla.org" ,
488
+ url : "https://hacks.mozilla.org/category/mdn/" ,
489
+ } ,
490
+ } ) ;
491
+ } ) ;
492
+
493
+ return items ;
494
+ } catch ( e ) {
495
+ const msg = "Couldn't fetch hacks.mozilla.org feed!" ;
496
+ if ( ! DEV_MODE ) {
497
+ console . error ( `Error: ${ msg } ` ) ;
498
+ throw e ;
499
+ }
500
+
501
+ console . warn ( `Warning: ${ msg } ` ) ;
502
+ return [ ] ;
503
+ }
504
+ }
0 commit comments