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:
@@ -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([]);
|
||||
|
||||
Reference in New Issue
Block a user