better error handling

This commit is contained in:
steven 2025-04-10 20:40:54 -04:00
parent fc633effeb
commit d4a7339005

View file

@ -33,10 +33,7 @@ let map=L.map("map",{center:[38.243,-85.647],zoom:11,layers:[osm]});
let layerControl=L.control.layers({"fetching gas prices...":osm},null,{collapsed:false}).addTo(map);
fetch("gas.csv").then(response=>{
layerControl.remove();
if(!response.ok){
L.control.layers({"fetch failed. try reloading?":osm},null,{collapsed:false}).addTo(map);
return
}
if(!response.ok){throw new Error(response.status)}
return response.text()
}).then(csv=>{
let storeLayers={},store,url;
@ -51,7 +48,10 @@ fetch("gas.csv").then(response=>{
}
})
L.control.layers(null,storeLayers,{collapsed:false}).addTo(map)
})
}).catch(error=>{
L.control.layers({"fetch failed. you could try reloading, otherwise email me.":osm},null,{collapsed:false}).addTo(map);
console.error(error)
}
</script>
</body>
</html>