From 9b75741f22c9f06dd24cd613318666fc67288522 Mon Sep 17 00:00:00 2001 From: "Engelbart Kai Sven (PEA4-Fe)" Date: Thu, 25 Feb 2021 11:45:38 +0100 Subject: [PATCH] Throw an error when a prediction cannot be found --- src/routes/prediction.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/routes/prediction.ts b/src/routes/prediction.ts index fc50d04..9fc2bf6 100644 --- a/src/routes/prediction.ts +++ b/src/routes/prediction.ts @@ -17,9 +17,10 @@ router.post('/prediction/new', (req, res, next) => { }); router.post('/prediction/compare', async (req, res, next) => { - const valA = (await PredictionModel.findOne({ name: req.body.nameA })).value; - const valB = (await PredictionModel.findOne({ name: req.body.nameB })).value; - res.json(valB - valA); + const valA = await PredictionModel.findOne({ name: req.body.nameA }); + const valB = await PredictionModel.findOne({ name: req.body.nameB }); + if(!valA || !valB) next(new Error("invalid prediction name")); + res.json(valB.value - valA.value); });