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:
ISA
2024-06-19 09:42:58 +02:00
parent 30ace5ad8a
commit a7b7e3f25a
2 changed files with 31 additions and 17 deletions

View File

@@ -1193,15 +1193,23 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
useEffect(() => {
const fetchPoiData = async () => {
const response = await fetch("/api/talas_v5_DB/pois/poi-icons");
const data = await response.json();
setPoiData(data);
//console.log("poiData icons:", data);
try {
const response = await fetch("/api/talas_v5_DB/pois/poi-icons");
if (!response.ok) {
throw new Error("Network response was not ok");
}
const data = await response.json();
setPoiData(data);
console.log("poiData data:", data);
console.log("poiData icons:", poiData);
} catch (error) {
console.error("Fehler beim Abrufen der poiData:", error);
}
};
fetchPoiData();
}, []);
//--------------------------------------------
useEffect(() => {
try {
if (map && poiLayerRef.current && isPoiTypLoaded) {
@@ -2088,13 +2096,13 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
try {
const response = await fetch(webserviceGisLinesStatusUrl);
const data = await response.json();
console.log("data.Statis: ", data);
//console.log("data.Statis: ", data);
const colorsByModule = {};
data.Statis.forEach((item) => {
colorsByModule[item.Modul] = item.PrioColor;
});
setLineColors(colorsByModule);
console.log("colorsByModule", colorsByModule);
//console.log("colorsByModule", colorsByModule);
} catch (error) {
console.error("Fehler beim Abrufen der linesColorApi Daten:", error);
}
@@ -2104,7 +2112,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
// Überwachen des lineColors Zustandes
useEffect(() => {
console.log("Aktualisierte lineColors", lineColors);
//console.log("Aktualisierte lineColors", lineColors);
}, [lineColors]);
const [linePositions, setLinePositions] = useState([]);