Skip to content

Commit

Permalink
Se ha añadido mensaje de error
Browse files Browse the repository at this point in the history
  • Loading branch information
CANCI0 committed Mar 7, 2024
1 parent 5541f4d commit 8080a75
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 4 additions & 3 deletions webapp/src/pages/Bateria/Bateria.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ const JuegoPreguntas = () => {
fetch("http://localhost:8003/questions?tematica=all&n=10000")
.then((response) => {
if (!response.ok) {
navigate("/home");
navigate("/home?error=1");
return;
}
response.json();
return response.json();
})
.then((data) => {
setPreguntas(data);
Expand All @@ -29,7 +30,7 @@ const JuegoPreguntas = () => {
})
.catch((error) => {
console.error("Error al obtener las preguntas:", error);
navigate("/home");
navigate("/home?error=1");
});
}, []);

Expand Down
7 changes: 4 additions & 3 deletions webapp/src/pages/Clasico/Clasico.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ const JuegoPreguntas = () => {
fetch("http://localhost:8003/questions?tematica=all&n=10")
.then((response) => {
if (!response.ok) {
navigate("/home");
navigate("/home?error=1");
return;
}
response.json();
return response.json();
})
.then((data) => {
setPreguntas(data);
Expand All @@ -38,7 +39,7 @@ const JuegoPreguntas = () => {
})
.catch((error) => {
console.error("Error al obtener las preguntas:", error);
navigate("/home");
navigate("/home?error=1");
});
}, []);

Expand Down
6 changes: 6 additions & 0 deletions webapp/src/pages/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import "./Home.css";
import Nav from '../../components/Nav/Nav.js';
import Footer from '../../components/Footer/Footer.js';
import { Link } from "react-router-dom";
import { useLocation } from "react-router-dom";

const Home = () => {
const location = useLocation();
const searchParams = new URLSearchParams(location.search);
const error = searchParams.get("error");

return (
<>
<Nav />
Expand All @@ -20,6 +25,7 @@ const Home = () => {
<Link to="pregunta">La pregunta caliente</Link>
<Link to="descubriendo">Descubriendo ciudades</Link> */}
</ul>
{error && <p>Hubo un error al cargar las preguntas. Inténtalo más tarde</p>}
</div>
<Footer />
</>
Expand Down

0 comments on commit 8080a75

Please sign in to comment.