feat: Pois icons ,Add error handling for fetch and database operations
- Added try-catch block in MapComponent.js to handle errors during fetch operation - Added try-catch block in API route to handle errors during database query This improves the robustness and error tolerance of the application by ensuring errors are properly caught and logged.
This commit is contained in:
@@ -2,35 +2,41 @@
|
||||
import mysql from "mysql";
|
||||
|
||||
const dbConfig = {
|
||||
//host: "10.10.0.13",
|
||||
//host: "localhost",
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_NAME,
|
||||
port: process.env.DB_PORT,
|
||||
};
|
||||
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
export default function handler(req, res) {
|
||||
if (req.method !== "GET") {
|
||||
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
|
||||
}
|
||||
|
||||
const query = `SELECT p.idPoi, i.path
|
||||
FROM poi p
|
||||
JOIN poiTyp pt ON p.idPoiTyp = pt.idPoiTyp
|
||||
JOIN poiicons i ON pt.icon = i.idpoiicons;`;
|
||||
FROM poi p
|
||||
JOIN poiTyp pt ON p.idPoiTyp = pt.idPoiTyp
|
||||
JOIN poiicons i ON pt.icon = i.idpoiicons;`;
|
||||
|
||||
connection.query(query, (error, results) => {
|
||||
if (error) {
|
||||
console.error("Fehler beim Abrufen der icons:", error);
|
||||
return res.status(500).json({ error: "Fehler beim Abrufen der icons" });
|
||||
try {
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
res.json(results);
|
||||
} catch (err) {
|
||||
console.error("Fehler beim Abrufen der icons:", err);
|
||||
res.status(500).json({ error: "Fehler beim Abrufen der icons" });
|
||||
}
|
||||
res.json(results);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user