Bugfix: Don't crash if no data could be found for a specific reading type

This commit is contained in:
Starbeamrainbowlabs 2019-06-30 21:41:28 +01:00
parent 902b17eed4
commit 659af6cf5d
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
2 changed files with 24 additions and 6 deletions

View File

@ -87,12 +87,20 @@ var pressure = {
"1100": "#BFED91" "1100": "#BFED91"
} }
}; };
var unknown = {
max: 100,
gradient: {
"0": "green",
"100": "red"
}
}
var specs = { var specs = {
PM10, PM25, PM10, PM25,
humidity, humidity,
temperature, temperature,
pressure pressure,
unknown
}; };
export default specs; export default specs;
@ -100,5 +108,6 @@ export {
PM10, PM25, PM10, PM25,
humidity, humidity,
temperature, temperature,
pressure pressure,
unknown
}; };

View File

@ -52,16 +52,25 @@ class VoronoiManager {
this.last_datetime = datetime; this.last_datetime = datetime;
this.last_reading_type = reading_type; this.last_reading_type = reading_type;
this.spec = Specs[reading_type]; this.spec = Specs[reading_type] || Specs["unknown"];
if(typeof this.spec.chroma == "undefined") if(typeof this.spec.chroma == "undefined")
this.spec.chroma = chroma.scale(Object.values(this.spec.gradient)) this.spec.chroma = chroma.scale(Object.values(this.spec.gradient))
.domain(Object.keys(this.spec.gradient)); .domain(Object.keys(this.spec.gradient));
this.guage.set_spec(this.spec); this.guage.set_spec(this.spec);
this.guage.render(); this.guage.render();
let dataset = JSON.parse(await GetFromUrl(
`${Config.api_root}?action=fetch-data&datetime=${encodeURIComponent(datetime.toISOString())}&reading_type=${encodeURIComponent(reading_type)}` let dataset = null;
)); try {
dataset = JSON.parse(await GetFromUrl(
`${Config.api_root}?action=fetch-data&datetime=${encodeURIComponent(datetime.toISOString())}&reading_type=${encodeURIComponent(reading_type)}`
));
}
catch(error) { // string
document.querySelector("main").classList.remove("working-visual");
alert(error);
throw new Error(error);
}
let result = []; let result = [];
for(let row of dataset) { for(let row of dataset) {