Enhancement: Better handle some beszel errors (#4493)

pull/4495/head
shamoon 4 weeks ago committed by GitHub
parent cc9b4782f2
commit fd05ae377c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -20,8 +20,20 @@ export default function Component({ service }) {
widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS);
}
if (systemsError) {
return <Container service={service} error={systemsError} />;
let system = null;
let finalError = systemsError;
if (systems && !systems.items) {
finalError = { message: "No items returned from beszel API" };
} else if (systems && systems.items && systemId) {
system = systems.items.find((item) => item.id === systemId);
if (!system) {
finalError = { message: `System with id ${systemId} not found` };
}
}
if (finalError) {
return <Container service={service} error={finalError} />;
}
if (!systems) {
@ -33,9 +45,7 @@ export default function Component({ service }) {
);
}
if (systemId) {
const system = systems.items.find((item) => item.id === systemId);
if (system) {
return (
<Container service={service}>
<Block label="beszel.name" value={system.name} />

@ -59,7 +59,7 @@ export default async function beszelProxyHandler(req, res) {
if (!token) {
[status, token] = await login(loginUrl, widget.username, widget.password, service);
if (status !== 200) {
logger.debug(`HTTP ${status} logging into Beszel: ${token}`);
logger.debug(`HTTP ${status} logging into Beszel: ${JSON.stringify(token)}`);
return res.status(status).send(token);
}
}
@ -72,13 +72,13 @@ export default async function beszelProxyHandler(req, res) {
},
});
if (status === 403) {
if ([400, 403].includes(status)) {
logger.debug(`HTTP ${status} retrieving data from Beszel, logging in and trying again.`);
cache.del(`${tokenCacheKey}.${service}`);
[status, token] = await login(loginUrl, widget.username, widget.password, service);
if (status !== 200) {
logger.debug(`HTTP ${status} logging into Beszel: ${data}`);
logger.debug(`HTTP ${status} logging into Beszel: ${JSON.stringify(data)}`);
return res.status(status).send(data);
}

Loading…
Cancel
Save