From 8ffdf38adb1b2b1d51ca27400177d684323df641 Mon Sep 17 00:00:00 2001 From: sergiollende Date: Thu, 21 Mar 2024 17:27:45 +0100 Subject: [PATCH] Changes wikidata call --- gatewayservice/gateway-service.js | 4 ---- webapp/src/stores/playing-store.ts | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index ef8f165..bb3a7c4 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -27,7 +27,6 @@ app.post('/login', async (req, res) => { const authResponse = await axios.post(userServiceUrl + '/auth/login', req.body); res.json(authResponse.data); } catch (error) { - res.status(error.response.status).json({ error: error.response.data.error }); console.error(error); } }); @@ -38,7 +37,6 @@ app.post('/adduser', async (req, res) => { const userResponse = await axios.post(userServiceUrl + '/user/adduser', req.body); res.json(userResponse.data); } catch (error) { - res.status(error.response.status).json({ error: error.response.data.error }); console.error(error); } }); @@ -49,7 +47,6 @@ app.post('/edituser', async (req, res) => { const userResponse = await axios.post(userServiceUrl + '/user/edituser', req.body); res.json(userResponse.data); } catch (error) { - res.status(error.response.status).json({ error: error.response.data.error }); console.error(error); } }); @@ -61,7 +58,6 @@ app.get('/WikiData/GetCapitalsQuestions', async (_req, res) => { const wikiResponse = await axios.get(wikidataServiceUrl + '/WikiData/GetCapitalsQuestions'); res.json(wikiResponse.data); } catch (error) { - res.status(error.response.status).json({ error: error.response.data.error }); console.error(error); } }); diff --git a/webapp/src/stores/playing-store.ts b/webapp/src/stores/playing-store.ts index a628d18..92c8cf1 100644 --- a/webapp/src/stores/playing-store.ts +++ b/webapp/src/stores/playing-store.ts @@ -1,4 +1,5 @@ +import axios from 'axios'; import {create} from 'zustand'; import { getCorrectlyAnsweredQuestions, getQuestionsAnswered } from '../services/auth-service'; @@ -58,14 +59,15 @@ interface GameQuestions{ const API_URL = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000'; -const retrieveQuestions = () => { - console.log(`${API_URL}`); - return fetch(`${API_URL}/WikiData/GetCapitalsQuestions`) - .then((response) => response.json()) - .catch((error) => { - console.error('There was a problem with the questions:', error); - return []; // Return an empty array in case of an error - }); +export const retrieveQuestions = async () => { + try { + let response = await axios.get(`${API_URL}/WikiData/GetCapitalsQuestions`); + console.log('response:', response); + return response.data.json(); + } catch (error) { + console.error('There was a problem with the questions:', error); + return []; + } }; export const useGameQuestions = create((set) => ({