Refactor Pokémon data fetching and validation logic; improve error handling and logging

This commit is contained in:
vista-man committed 2025-03-26 10:25:08 +01:00
1 parent 6e06965bc0
commit 5b4fcda9d6
4 files changed
+202 -14

No files matched your search

+4 -2
View File
@@ -28,8 +28,10 @@ document.addEventListener("DOMContentLoaded", () => {
function fetchPokemons() {
console.log("Fetching Pokémon data from server...");
fetch(`./get-pokemon.php`)
.then((response) => response.json())
.then((data) => {
.then((response) => response.text())
.then((text) => {
console.log("Server response:", text);
const data = JSON.parse(text);
if (Array.isArray(data)) {
allPokemons = data;
localStorage.setItem("pokemons", JSON.stringify(allPokemons));