@@ -40,44 +40,42 @@ router.get('/repos', (req: Request, res: Response, next: NextFunction) => {
40
40
} ) ;
41
41
42
42
router . get ( '/contributors' , async ( req : Request , res : Response , next : NextFunction ) => {
43
- try {
44
- const body = await cache . wrap (
45
- 'github/contributors' ,
46
- async ( ) => {
47
- const getDetails = async login => {
48
- const { data } = await axios ( `${ apiBaseUrl } /users/${ login } ` , {
49
- headers : {
50
- ...headers ,
51
- 'Content-Type' : 'application/json; charset=utf-8' ,
52
- 'User-Agent' : `${ name } /${ version } ` ,
53
- } ,
54
- } ) ;
55
- return data as IContributor ;
56
- } ;
57
-
58
- let promises = [ ] ;
59
- let contributors = await readContributorFile ( ) ;
60
- contributors . forEach ( i => {
61
- promises . push ( getDetails ( i . login ) ) ;
43
+ const body = await cache . wrap (
44
+ 'github/contributors' ,
45
+ async ( ) => {
46
+ const getDetails = async login => {
47
+ const { data } = await axios ( `${ apiBaseUrl } /users/${ login } ` , {
48
+ headers : {
49
+ ...headers ,
50
+ 'Content-Type' : 'application/json; charset=utf-8' ,
51
+ 'User-Agent' : `${ name } /${ version } ` ,
52
+ } ,
62
53
} ) ;
54
+ return data as IContributor ;
55
+ } ;
63
56
64
- return await Promise . all ( promises )
65
- . then ( values => {
66
- return values as IContributor [ ] ;
67
- } )
68
- . catch ( err => {
69
- console . log ( err ) ;
70
- next ( err ) ;
71
- } ) ;
72
- } ,
73
- { ttl } ,
74
- ) ;
57
+ let promises = [ ] ;
58
+ let contributors = await readContributorFile ( ) ;
59
+ contributors . forEach ( i => {
60
+ promises . push (
61
+ getDetails ( i . login )
62
+ . then ( data => data )
63
+ . catch ( err => {
64
+ console . log ( err ) ;
65
+ return err ;
66
+ } ) ,
67
+ ) ;
68
+ } ) ;
75
69
76
- return res . status ( 200 ) . json ( body ) ;
77
- } catch ( err ) {
78
- console . log ( err ) ;
79
- return next ( err ) ;
80
- }
70
+ return await Promise . all ( promises ) . then ( values => {
71
+ values = values . filter ( value => ! ( value instanceof Error ) ) ;
72
+ return values as IContributor [ ] ;
73
+ } ) ;
74
+ } ,
75
+ { ttl } ,
76
+ ) ;
77
+
78
+ return res . status ( 200 ) . json ( body ) ;
81
79
82
80
function readContributorFile ( ) : Promise < IContributor [ ] > {
83
81
return new Promise ( resolve => {
0 commit comments