sysutils/nut: do not crash on this edge case, all I can test

This commit is contained in:
Franco Fichtner 2024-12-06 17:50:14 +01:00
parent f2a59dad2f
commit fc230cc927
2 changed files with 6 additions and 0 deletions

View file

@ -31,6 +31,7 @@
<status_boost>UPS is boosting voltage</status_boost>
<status_fsd>Forced Shutdown</status_fsd>
<unconfigured>Nut is not started. Click to configure Nut.</unconfigured>
<misconfigured>Nut is not returning a status. Click to reconfigure Nut.</misconfigured>
<netclient_unconfigured>This widget only works with the Netclient driver. Click to configure the Netclient driver.</netclient_unconfigured>
<netclient_remote_server>Remote NUT Server</netclient_remote_server>
<time_hours>h</time_hours>

View file

@ -71,6 +71,11 @@ export default class NutNetclient extends BaseTableWidget {
// Fetch the UPS status data from the server.
const { response: nut_ups_status_response } = await this.ajaxCall(`/api/nut/${'diagnostics/upsstatus'}`);
if (!nut_ups_status_response) {
$('#nut-table').html(`<a href="/ui/nut/index">${this.translations.misconfigured}</a>`);
return;
}
// Parse the UPS status data into a key-value object.
const nut_ups_status = nut_ups_status_response.split('\n').reduce((acc, line) => {
const [key, value] = line.split(': ');