Fixed a mess I wrote last night. Ahahaha!

This commit is contained in:
Alexander Andreev 2021-02-17 19:34:44 +04:00
parent d3b298ee8b
commit de78ad5d31
Signed by: Arav
GPG Key ID: 610DF2574456329F

View File

@ -10,8 +10,16 @@ const config = require("./config");
const util = require("./util"); const util = require("./util");
async function getRadioStatus() { async function getRadioStatus() {
let status = await fetch('http://radio.home/status-json.xsl').then(r => r.json()) try {
.catch(() => { let status = await fetch('http://radio.home/status-json.xsl').then(r => r.json());
return {
server_start_iso8601: status.icestats.server_start_iso8601,
server_start_date: util.datetime(status.icestats.server_start_iso8601, util.post_date_format),
song: `${status.icestats.source.artist} - ${status.icestats.source.title}`,
listener_peak: status.icestats.source.listener_peak,
listeners: status.icestats.source.listeners
}
} catch {
return { return {
server_start_iso8601: "n/a", server_start_iso8601: "n/a",
server_start_date: "n/a", server_start_date: "n/a",
@ -19,13 +27,6 @@ async function getRadioStatus() {
listener_peak: "n/a", listener_peak: "n/a",
listeners: "n/a" listeners: "n/a"
} }
});
return {
server_start_iso8601: status.icestats.server_start_iso8601,
server_start_date: util.datetime(status.icestats.server_start_iso8601, util.post_date_format),
song: `${status.icestats.source.artist} - ${status.icestats.source.title}`,
listener_peak: status.icestats.source.listener_peak,
listeners: status.icestats.source.listeners
} }
} }