Skip to content

Commit

Permalink
Adding in optimise filters and a try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulMcCaffertyPA committed Mar 3, 2022
1 parent 9c8b083 commit d46adab
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/resources/dataset/v1/dataset.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ const datasetLimiter = rateLimit({

// This api triggers Aridhia Script (collect datasets from Aridhi API and updates the DB accordingly)
router.post('/aridhia', async (req, res) => {

// check for a key. return 401, since user unauthorised (caching key is missing or not matched)
let parsedBody = req.header('content-type') === 'application/json' ? req.body : JSON.parse(req.body);
if (parsedBody.key !== process.env.cachingkey)
return res.status(401).json({ success: false, error: 'Caching could not be started.' });

const ac = new AridhiaController();
ac.main();

return res.status(200).json({ success: true, message: 'Caching started' })
try {
// check for a key. return 401, since user unauthorised (caching key is missing or not matched)
let parsedBody = req.header('content-type') === 'application/json' ? req.body : JSON.parse(req.body);
if (parsedBody.key !== process.env.cachingkey) return res.status(401).json({ success: false, error: 'Caching could not be started.' });

const ac = new AridhiaController();
ac.main().then(() => {
filtersService.optimiseFilters('dataset');
});

return res.status(200).json({ success: true, message: 'Caching started' });
} catch (err) {
Sentry.captureException(err);
console.error(err.message);
return res.status(500).json({ success: false, message: 'Caching failed' });
}
});

router.post('/', async (req, res) => {
Expand Down Expand Up @@ -251,4 +257,4 @@ router.get('/', async (req, res) => {
});
});

module.exports = router;
module.exports = router;

0 comments on commit d46adab

Please sign in to comment.