Skip to content

Commit

Permalink
fix(web): add error handling and log error
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed May 14, 2017
1 parent b1cd075 commit b52f33d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/Web.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ app.get('/', (req, res) => {
res.render('index', { bot, repos, status, statusColor });
});

app.post(['/', '/gitlab'], (req, res) => {
app.post('/', (req, res) => {
const event = req.headers['x-gitlab-event'];
const eventName = event.replace(` Hook`, '').replace(/ /g, '_').toLowerCase();
const eventName = event && event.replace(` Hook`, '').replace(/ /g, '_').toLowerCase();
const data = req.body;

if (!event || !data || !data.project) return res.status(403).send('Invalid data. Plz use Gitlab webhooks.');
Expand Down Expand Up @@ -62,6 +62,12 @@ app.post(['/', '/gitlab'], (req, res) => {
});
});

app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
if (err) Log.error(err);
res.status(500);
res.send(err.stack);
});

app.listen(port, ip, () => {
Log.info(`Express | Listening on ${ip || 'localhost'}:${port}`);
});
Expand Down

0 comments on commit b52f33d

Please sign in to comment.