Error handling for fetching Github access token
This commit is contained in:
parent
fc49213b01
commit
c16ea51769
@ -214,14 +214,20 @@ module.exports = async function(robot, kredits) {
|
|||||||
res.status(400).json({});
|
res.status(400).json({});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const githubResponse = await fetch('https://api.github.com/user', {
|
try {
|
||||||
headers: {
|
const githubResponse = await fetch('https://api.github.com/user', {
|
||||||
'Accept': 'application/vnd.github.v3+json',
|
headers: {
|
||||||
'Authorization': `token ${accessToken}`
|
'Accept': 'application/vnd.github.v3+json',
|
||||||
}
|
'Authorization': `token ${accessToken}`
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
robot.logger.error('[hubot-kredits] Fetching user data from GitHub failed:', error);
|
||||||
|
res.status(500).json({ error });
|
||||||
|
};
|
||||||
|
|
||||||
if (githubResponse.status >= 300) {
|
if (githubResponse.status >= 300) {
|
||||||
res.sendStatus(githubResponse.status);
|
res.status(githubResponse.status).json({});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const user = await githubResponse.json();
|
const user = await githubResponse.json();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user