- 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.
43 lines
1.0 KiB
JavaScript
43 lines
1.0 KiB
JavaScript
// pages/api/talas_v5_DB/pois/poi-icons.js
|
|
import mysql from "mysql";
|
|
|
|
const dbConfig = {
|
|
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;`;
|
|
|
|
connection.query(query, (error, results) => {
|
|
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" });
|
|
}
|
|
});
|
|
}
|