Skip to content

Commit 2bb5809

Browse files
authored
Merge pull request #220 from likelionWonHo/master
[Modify] modify contributor handler
2 parents 300fd01 + a66e11d commit 2bb5809

File tree

1 file changed

+33
-35
lines changed

1 file changed

+33
-35
lines changed

handlers/github.ts

+33-35
Original file line numberDiff line numberDiff line change
@@ -40,44 +40,42 @@ router.get('/repos', (req: Request, res: Response, next: NextFunction) => {
4040
});
4141

4242
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+
},
6253
});
54+
return data as IContributor;
55+
};
6356

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+
});
7569

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);
8179

8280
function readContributorFile(): Promise<IContributor[]> {
8381
return new Promise(resolve => {

0 commit comments

Comments
 (0)