mirror of
https://github.com/Alvin-Zilverstand/pokedex.git
synced 2026-03-06 13:25:11 +01:00
Add error logging for database connection failures and Pokémon retrieval
This commit is contained in:
@@ -4,9 +4,19 @@ $username = "database1";
|
|||||||
$password = "181t$1lJg";
|
$password = "181t$1lJg";
|
||||||
$dbname = "pokedex1";
|
$dbname = "pokedex1";
|
||||||
|
|
||||||
|
// Set the custom log file path
|
||||||
|
$logFile = __DIR__ . '/error_log.txt';
|
||||||
|
|
||||||
|
// Function to log messages
|
||||||
|
function logMessage($message) {
|
||||||
|
global $logFile;
|
||||||
|
error_log($message . "\n", 3, $logFile);
|
||||||
|
}
|
||||||
|
|
||||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||||
|
|
||||||
if ($conn->connect_error) {
|
if ($conn->connect_error) {
|
||||||
|
logMessage("Connection failed: " . $conn->connect_error);
|
||||||
die("Connection failed: " . $conn->connect_error);
|
die("Connection failed: " . $conn->connect_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,6 +42,7 @@ if (isset($_GET['id'])) {
|
|||||||
$pokemon['abilities'] = explode(',', $pokemon['abilities']);
|
$pokemon['abilities'] = explode(',', $pokemon['abilities']);
|
||||||
echo json_encode($pokemon);
|
echo json_encode($pokemon);
|
||||||
} else {
|
} else {
|
||||||
|
logMessage("No Pokémon found for ID: $id");
|
||||||
echo json_encode(["error" => "No Pokémon found"]);
|
echo json_encode(["error" => "No Pokémon found"]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ async function fetchPokemonDataBeforeRedirect(id) {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch Pokémon data before redirect:", error);
|
console.error(`Failed to fetch Pokémon data before redirect for ID ${id}:`, error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user