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