Skip to content

Commit

Permalink
fix: Catch unhandled exceptions (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjayprabhu authored Oct 12, 2023
1 parent f133223 commit c11828c
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ app.get('/transfers', async (req, res) => {
if (req.query.fid) {
filterOpts.fid = parseInt(req.query.fid.toString());
}
const transfers = await getTransferHistory(filterOpts, db);
res.send({ transfers });
try {
const transfers = await getTransferHistory(filterOpts, db);
res.send({ transfers });
} catch (e) {
res.status(400).send({ error: 'Unable to get transfers' }).end();
log.error(e, 'Unable to get transfers for filter', filterOpts);
return;
}
});

app.get('/transfers/current', async (req, res) => {
Expand All @@ -79,12 +85,18 @@ app.get('/transfers/current', async (req, res) => {
res.status(404).send({ error: 'Could not resolve current name' }).end();
return;
}
const transfer = await getLatestTransfer(name, db);
if (!transfer || transfer.to === 0) {
res.status(404).send({ error: 'No transfer found' }).end();
try {
const transfer = await getLatestTransfer(name, db);
if (!transfer || transfer.to === 0) {
res.status(404).send({ error: 'No transfer found' }).end();
return;
}
res.send({ transfer });
} catch (e) {
res.status(400).send({ error: 'Unable to get transfer' }).end();
log.error(e, 'Unable to get transfers for query', req.query);
return;
}
res.send({ transfer });
});

app.post('/transfers', async (req, res) => {
Expand Down

0 comments on commit c11828c

Please sign in to comment.