From 777ee1365764a9fe7256604fa8242f89d059031f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20M=C3=A9ndez=20Murias?= Date: Fri, 23 Feb 2024 18:25:57 +0100 Subject: [PATCH] Control exceptions on question generation service --- .../questionGenerationService.js | 21 ++++++++++++++++--- webapp/README.md | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/question_generator/questionGenerationService.js b/question_generator/questionGenerationService.js index 8ec72f28..9f889b35 100644 --- a/question_generator/questionGenerationService.js +++ b/question_generator/questionGenerationService.js @@ -12,13 +12,28 @@ app.use(bodyParser.json()); app.get('/api/questions/create', async (req, res) => { - res.status(200).json(await generalTemplate.getRandomQuestion()) + try { + const randomQuestion = await generalTemplate.getRandomQuestion(); + res.status(200).json(randomQuestion); + } catch (error) { + res.status(500).json({ error: 'Internal Server Error' }); + } }); app.get('/api/questions/planets/create', async (req, res) => { - res.status(200).json(await planetTemplate.getRandomQuestion()) + try { + const randomQuestion = await planetTemplate.getRandomQuestion(); + res.status(200).json(randomQuestion); + } catch (error) { + res.status(500).json({ error: 'Internal Server Error' }); + } }); app.get('/api/questions/cities/create', async (req, res) => { - res.status(200).json(await citiesTemplate.getRandomQuestion()) + try { + const randomQuestion = await citiesTemplate.getRandomQuestion(); + res.status(200).json(randomQuestion); + } catch (error) { + res.status(500).json({ error: 'Internal Server Error' }); + } }); generalTemplate.loadData(); diff --git a/webapp/README.md b/webapp/README.md index 9568101e..7d9ddf6b 100644 --- a/webapp/README.md +++ b/webapp/README.md @@ -92,6 +92,7 @@ unit-tests: - run: npm --prefix webapp ci - run: npm --prefix users/authservice test -- --coverage - run: npm --prefix users/userservice test -- --coverage + - run: npm --prefix question_generator/questionGenerationService test -- --coverage - run: npm --prefix gatewayservice test -- --coverage - run: npm --prefix webapp test -- --coverage - name: Analyze with SonarCloud