Fix: refresh beszel token if empty list is returned (#5292)

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
hank 2025-05-20 20:40:59 -04:00 committed by GitHub
parent 6abb3d8758
commit f8768711da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -72,8 +72,23 @@ export default async function beszelProxyHandler(req, res) {
},
});
if ([400, 403].includes(status)) {
logger.debug(`HTTP ${status} retrieving data from Beszel, logging in and trying again.`);
const badRequest = [400, 403].includes(status);
const text = data.toString("utf-8");
let isEmpty = false;
try {
const json = JSON.parse(text);
isEmpty = Array.isArray(json.items) && json.items.length === 0;
} catch (err) {
logger.debug("Failed to parse Beszel response JSON:", err);
}
if (badRequest || isEmpty) {
if (badRequest) {
logger.debug(`HTTP ${status} retrieving data from Beszel, logging in and trying again.`);
} else {
logger.debug(`Received empty list from Beszel, logging in and trying again.`);
}
cache.del(`${tokenCacheKey}.${service}`);
[status, token] = await login(loginUrl, widget.username, widget.password, service);