From 2fae39e3ceac127253d8c6f7ffc37c995593b62d Mon Sep 17 00:00:00 2001 From: Matt Sullivan Date: Fri, 21 Jun 2024 09:04:50 +0100 Subject: [PATCH 1/6] Improve error handling for Glances widgets when host is unreachable --- src/widgets/glances/components/container.jsx | 11 ++++- src/widgets/glances/components/error.jsx | 7 ---- src/widgets/glances/metrics/cpu.jsx | 7 ++-- src/widgets/glances/metrics/disk.jsx | 10 ++--- src/widgets/glances/metrics/fs.jsx | 10 ++--- src/widgets/glances/metrics/gpu.jsx | 43 ++++++++++++-------- src/widgets/glances/metrics/info.jsx | 36 +++++++++------- src/widgets/glances/metrics/memory.jsx | 8 ++-- src/widgets/glances/metrics/net.jsx | 10 ++--- src/widgets/glances/metrics/process.jsx | 8 ++-- src/widgets/glances/metrics/sensor.jsx | 10 ++--- 11 files changed, 83 insertions(+), 77 deletions(-) delete mode 100644 src/widgets/glances/components/error.jsx diff --git a/src/widgets/glances/components/container.jsx b/src/widgets/glances/components/container.jsx index 8a72a1b316e..f023dc85623 100644 --- a/src/widgets/glances/components/container.jsx +++ b/src/widgets/glances/components/container.jsx @@ -1,10 +1,19 @@ -export default function Container({ children, chart = true, className = "" }) { +import { useContext } from "react"; +import { useTranslation } from "next-i18next"; +import { SettingsContext } from "utils/contexts/settings"; +import { Settings } from "luxon"; + +export default function Container({ service, children, chart = true, error = false, className = "" }) { + const { t } = useTranslation(); + const { settings } = useContext(SettingsContext); + const hideErrors = (service.widget.hide_errors || settings.hideErrors) return (
{children}
{chart &&
} {!chart &&
} + {error && !hideErrors &&
{t("widget.api_error")}
}
); } diff --git a/src/widgets/glances/components/error.jsx b/src/widgets/glances/components/error.jsx deleted file mode 100644 index d88a17c0ea5..00000000000 --- a/src/widgets/glances/components/error.jsx +++ /dev/null @@ -1,7 +0,0 @@ -import { useTranslation } from "next-i18next"; - -export default function Error() { - const { t } = useTranslation(); - - return
{t("widget.api_error")}
; -} diff --git a/src/widgets/glances/metrics/cpu.jsx b/src/widgets/glances/metrics/cpu.jsx index 553517bace7..fbf8e1ae668 100644 --- a/src/widgets/glances/metrics/cpu.jsx +++ b/src/widgets/glances/metrics/cpu.jsx @@ -2,7 +2,6 @@ import dynamic from "next/dynamic"; import { useState, useEffect } from "react"; import { useTranslation } from "next-i18next"; -import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -40,7 +39,7 @@ export default function Component({ service }) { if (error) { return ( - + ); @@ -48,14 +47,14 @@ export default function Component({ service }) { if (!data) { return ( - + - ); } return ( - + {chart && ( - + ); } if (!data) { return ( - + - ); @@ -72,7 +70,7 @@ export default function Component({ service }) { if (!diskData) { return ( - + - ); @@ -82,7 +80,7 @@ export default function Component({ service }) { const currentRate = diskRates[diskRates.length - 1]; return ( - + {chart && ( - + ); } if (!data) { return ( - + - ); @@ -39,14 +37,14 @@ export default function Component({ service }) { if (!fsData) { return ( - + - ); } return ( - + {chart && (
{ if (data) { - // eslint-disable-next-line eqeqeq - const gpuData = data.find((item) => item[item.key] == gpuName); - - if (gpuData) { - setDataPoints((prevDataPoints) => { - const newDataPoints = [...prevDataPoints, { a: gpuData.mem, b: gpuData.proc }]; - if (newDataPoints.length > pointsLimit) { - newDataPoints.shift(); - } - return newDataPoints; - }); + + if (data.hasOwnProperty("error")) { + return ( + + + ) } + + else { + // eslint-disable-next-line eqeqeq + const gpuData = data.find((item) => item[item.key] == gpuName); + + if (gpuData) { + setDataPoints((prevDataPoints) => { + const newDataPoints = [...prevDataPoints, { a: gpuData.mem, b: gpuData.proc }]; + if (newDataPoints.length > pointsLimit) { + newDataPoints.shift(); + } + return newDataPoints; + }); + } + } + } }, [data, gpuName, pointsLimit]); if (error) { return ( - - + ); } if (!data) { return ( - + - ); @@ -63,14 +72,14 @@ export default function Component({ service }) { if (!gpuData) { return ( - + - ); } return ( - + {chart && ( - + ); } if (systemError) { return ( - - + ); } const dataCharts = []; + if (quicklookData) { - quicklookData.percpu.forEach((cpu, index) => { - dataCharts.push({ - name: `CPU ${index}`, - cpu: cpu.total, - mem: quicklookData.mem, - swap: quicklookData.swap, - proc: quicklookData.cpu, + if (quicklookData.hasOwnProperty("error")) { + const quicklookError = true; + return ( + + + ); + } + else { + quicklookData.percpu.forEach((cpu, index) => { + dataCharts.push({ + name: `CPU ${index}`, + cpu: cpu.total, + mem: quicklookData.mem, + swap: quicklookData.swap, + proc: quicklookData.cpu, + }); }); - }); + } + } return ( - + {quicklookData && quicklookData.cpu_name && chart && (
{quicklookData.cpu_name}
diff --git a/src/widgets/glances/metrics/memory.jsx b/src/widgets/glances/metrics/memory.jsx index 49046a5fcc3..d3f3e2f8d87 100644 --- a/src/widgets/glances/metrics/memory.jsx +++ b/src/widgets/glances/metrics/memory.jsx @@ -2,7 +2,6 @@ import dynamic from "next/dynamic"; import { useState, useEffect } from "react"; import { useTranslation } from "next-i18next"; -import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -39,22 +38,21 @@ export default function Component({ service }) { if (error) { return ( - - + ); } if (!data) { return ( - + - ); } return ( - + {chart && ( - + ); } if (!data) { return ( - + - ); @@ -72,14 +70,14 @@ export default function Component({ service }) { if (!interfaceData) { return ( - + - ); } return ( - + {chart && ( - + ); } if (!data) { return ( - + - ); @@ -49,7 +47,7 @@ export default function Component({ service }) { data.splice(chart ? 5 : 1); return ( - +
diff --git a/src/widgets/glances/metrics/sensor.jsx b/src/widgets/glances/metrics/sensor.jsx index e0f679c13a3..df23ce99f6d 100644 --- a/src/widgets/glances/metrics/sensor.jsx +++ b/src/widgets/glances/metrics/sensor.jsx @@ -2,7 +2,6 @@ import dynamic from "next/dynamic"; import { useState, useEffect } from "react"; import { useTranslation } from "next-i18next"; -import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -40,15 +39,14 @@ export default function Component({ service }) { if (error) { return ( - - + ); } if (!data) { return ( - + - ); @@ -58,14 +56,14 @@ export default function Component({ service }) { if (!sensorData) { return ( - + - ); } return ( - + {chart && ( Date: Sat, 22 Jun 2024 09:54:50 +0100 Subject: [PATCH 2/6] Reintroduce Error component --- src/widgets/glances/components/container.jsx | 6 +++--- src/widgets/glances/components/error.jsx | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 src/widgets/glances/components/error.jsx diff --git a/src/widgets/glances/components/container.jsx b/src/widgets/glances/components/container.jsx index f023dc85623..df9e9bdb939 100644 --- a/src/widgets/glances/components/container.jsx +++ b/src/widgets/glances/components/container.jsx @@ -1,19 +1,19 @@ import { useContext } from "react"; import { useTranslation } from "next-i18next"; import { SettingsContext } from "utils/contexts/settings"; -import { Settings } from "luxon"; +import Error from "./error" export default function Container({ service, children, chart = true, error = false, className = "" }) { const { t } = useTranslation(); const { settings } = useContext(SettingsContext); - const hideErrors = (service.widget.hide_errors || settings.hideErrors) + const hideErrors = (settings.hideErrors || service.widget.hide_errors) return (
{children}
{chart &&
} {!chart &&
} - {error && !hideErrors &&
{t("widget.api_error")}
} + {error && !hideErrors && }
); } diff --git a/src/widgets/glances/components/error.jsx b/src/widgets/glances/components/error.jsx new file mode 100644 index 00000000000..b0c21e9663e --- /dev/null +++ b/src/widgets/glances/components/error.jsx @@ -0,0 +1,7 @@ +import { useTranslation } from "next-i18next"; + +export default function Error() { + const { t } = useTranslation(); + + return
{t("widget.api_error")}
; +} \ No newline at end of file From 4dde54a631b68294d823c30d4107c139c48de543 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 22 Jun 2024 07:19:02 -0700 Subject: [PATCH 3/6] Clean this up --- src/widgets/glances/components/container.jsx | 11 +---- src/widgets/glances/components/error.jsx | 16 +++++-- src/widgets/glances/metrics/cpu.jsx | 9 ++-- src/widgets/glances/metrics/disk.jsx | 15 +++--- src/widgets/glances/metrics/fs.jsx | 10 ++-- src/widgets/glances/metrics/gpu.jsx | 48 ++++++++------------ src/widgets/glances/metrics/info.jsx | 39 +++++++--------- src/widgets/glances/metrics/memory.jsx | 8 ++-- src/widgets/glances/metrics/net.jsx | 15 +++--- src/widgets/glances/metrics/process.jsx | 8 ++-- src/widgets/glances/metrics/sensor.jsx | 15 +++--- 11 files changed, 98 insertions(+), 96 deletions(-) diff --git a/src/widgets/glances/components/container.jsx b/src/widgets/glances/components/container.jsx index df9e9bdb939..8a72a1b316e 100644 --- a/src/widgets/glances/components/container.jsx +++ b/src/widgets/glances/components/container.jsx @@ -1,19 +1,10 @@ -import { useContext } from "react"; -import { useTranslation } from "next-i18next"; -import { SettingsContext } from "utils/contexts/settings"; -import Error from "./error" - -export default function Container({ service, children, chart = true, error = false, className = "" }) { - const { t } = useTranslation(); - const { settings } = useContext(SettingsContext); - const hideErrors = (settings.hideErrors || service.widget.hide_errors) +export default function Container({ children, chart = true, className = "" }) { return (
{children}
{chart &&
} {!chart &&
} - {error && !hideErrors && }
); } diff --git a/src/widgets/glances/components/error.jsx b/src/widgets/glances/components/error.jsx index b0c21e9663e..1ee1ebcb324 100644 --- a/src/widgets/glances/components/error.jsx +++ b/src/widgets/glances/components/error.jsx @@ -1,7 +1,17 @@ import { useTranslation } from "next-i18next"; +import { useContext } from "react"; -export default function Error() { +import { SettingsContext } from "utils/contexts/settings"; + +export default function Error({ service, error }) { const { t } = useTranslation(); + const { settings } = useContext(SettingsContext); + + if (error) { + if (settings.hideErrors || service?.widget.hide_errors) { + return null; + } - return
{t("widget.api_error")}
; -} \ No newline at end of file + return
{t("widget.api_error")}
; + } +} diff --git a/src/widgets/glances/metrics/cpu.jsx b/src/widgets/glances/metrics/cpu.jsx index fbf8e1ae668..9c5bf6e61cf 100644 --- a/src/widgets/glances/metrics/cpu.jsx +++ b/src/widgets/glances/metrics/cpu.jsx @@ -4,6 +4,7 @@ import { useTranslation } from "next-i18next"; import Container from "../components/container"; import Block from "../components/block"; +import Error from "../components/error"; import useWidgetAPI from "utils/proxy/use-widget-api"; @@ -39,22 +40,22 @@ export default function Component({ service }) { if (error) { return ( - - + + ); } if (!data) { return ( - + - ); } return ( - + {chart && ( { - if (data) { + if (data && !data.error) { const diskData = data.find((item) => item.disk_name === diskName); setDataPoints((prevDataPoints) => { @@ -51,16 +52,18 @@ export default function Component({ service }) { setRatePoints(calculateRates(dataPoints)); }, [dataPoints]); - if (error) { + if (error || (data && data.error)) { + const finalError = error || data.error; return ( - + + ); } if (!data) { return ( - + - ); @@ -70,7 +73,7 @@ export default function Component({ service }) { if (!diskData) { return ( - + - ); @@ -80,7 +83,7 @@ export default function Component({ service }) { const currentRate = diskRates[diskRates.length - 1]; return ( - + {chart && ( + + ); } if (!data) { return ( - + - ); @@ -37,14 +39,14 @@ export default function Component({ service }) { if (!fsData) { return ( - + - ); } return ( - + {chart && (
{ - if (data) { - - if (data.hasOwnProperty("error")) { - return ( - - - ) - } - - else { - // eslint-disable-next-line eqeqeq - const gpuData = data.find((item) => item[item.key] == gpuName); - - if (gpuData) { - setDataPoints((prevDataPoints) => { - const newDataPoints = [...prevDataPoints, { a: gpuData.mem, b: gpuData.proc }]; - if (newDataPoints.length > pointsLimit) { - newDataPoints.shift(); - } - return newDataPoints; - }); - } + if (data && !data.error) { + // eslint-disable-next-line eqeqeq + const gpuData = data.find((item) => item[item.key] == gpuName); + + if (gpuData) { + setDataPoints((prevDataPoints) => { + const newDataPoints = [...prevDataPoints, { a: gpuData.mem, b: gpuData.proc }]; + if (newDataPoints.length > pointsLimit) { + newDataPoints.shift(); + } + return newDataPoints; + }); } - } }, [data, gpuName, pointsLimit]); - if (error) { + if (error || (data && data.error)) { + const finalError = error || data.error; return ( - + + ); } if (!data) { return ( - + - ); @@ -72,14 +64,14 @@ export default function Component({ service }) { if (!gpuData) { return ( - + - ); } return ( - + {chart && ( + + ); } if (systemError) { return ( - + + ); } const dataCharts = []; - if (quicklookData) { - if (quicklookData.hasOwnProperty("error")) { - const quicklookError = true; - return ( - - - ); - } - else { - quicklookData.percpu.forEach((cpu, index) => { - dataCharts.push({ - name: `CPU ${index}`, - cpu: cpu.total, - mem: quicklookData.mem, - swap: quicklookData.swap, - proc: quicklookData.cpu, - }); + quicklookData.percpu.forEach((cpu, index) => { + dataCharts.push({ + name: `CPU ${index}`, + cpu: cpu.total, + mem: quicklookData.mem, + swap: quicklookData.swap, + proc: quicklookData.cpu, }); - } - + }); } return ( - + {quicklookData && quicklookData.cpu_name && chart && (
{quicklookData.cpu_name}
diff --git a/src/widgets/glances/metrics/memory.jsx b/src/widgets/glances/metrics/memory.jsx index d3f3e2f8d87..87782120069 100644 --- a/src/widgets/glances/metrics/memory.jsx +++ b/src/widgets/glances/metrics/memory.jsx @@ -2,6 +2,7 @@ import dynamic from "next/dynamic"; import { useState, useEffect } from "react"; import { useTranslation } from "next-i18next"; +import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -38,21 +39,22 @@ export default function Component({ service }) { if (error) { return ( - + + ); } if (!data) { return ( - + - ); } return ( - + {chart && ( { - if (data) { + if (data && !data.error) { const interfaceData = data.find((item) => item[item.key] === interfaceName); if (interfaceData) { @@ -51,16 +52,18 @@ export default function Component({ service }) { } }, [data, interfaceName, pointsLimit, rxKey, txKey]); - if (error) { + if (error || (data && data.error)) { + const finalError = error || data.error; return ( - + + ); } if (!data) { return ( - + - ); @@ -70,14 +73,14 @@ export default function Component({ service }) { if (!interfaceData) { return ( - + - ); } return ( - + {chart && ( + + ); } if (!data) { return ( - + - ); @@ -47,7 +49,7 @@ export default function Component({ service }) { data.splice(chart ? 5 : 1); return ( - +
diff --git a/src/widgets/glances/metrics/sensor.jsx b/src/widgets/glances/metrics/sensor.jsx index df23ce99f6d..0b42e3d6426 100644 --- a/src/widgets/glances/metrics/sensor.jsx +++ b/src/widgets/glances/metrics/sensor.jsx @@ -2,6 +2,7 @@ import dynamic from "next/dynamic"; import { useState, useEffect } from "react"; import { useTranslation } from "next-i18next"; +import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -25,7 +26,7 @@ export default function Component({ service }) { }); useEffect(() => { - if (data) { + if (data && !data.error) { const sensorData = data.find((item) => item.label === sensorName); setDataPoints((prevDataPoints) => { const newDataPoints = [...prevDataPoints, { value: sensorData.value }]; @@ -37,16 +38,18 @@ export default function Component({ service }) { } }, [data, sensorName, pointsLimit]); - if (error) { + if (error || (data && data.error)) { + const finalError = error || data.error; return ( - + + ); } if (!data) { return ( - + - ); @@ -56,14 +59,14 @@ export default function Component({ service }) { if (!sensorData) { return ( - + - ); } return ( - + {chart && ( Date: Sat, 22 Jun 2024 13:03:35 -0700 Subject: [PATCH 4/6] More consistent with other implementations --- src/widgets/glances/components/container.jsx | 12 +++++++++++- src/widgets/glances/components/error.jsx | 14 ++------------ src/widgets/glances/metrics/cpu.jsx | 7 +------ src/widgets/glances/metrics/disk.jsx | 7 +------ src/widgets/glances/metrics/fs.jsx | 7 +------ src/widgets/glances/metrics/gpu.jsx | 7 +------ src/widgets/glances/metrics/info.jsx | 13 ++----------- src/widgets/glances/metrics/memory.jsx | 7 +------ src/widgets/glances/metrics/net.jsx | 7 +------ src/widgets/glances/metrics/process.jsx | 7 +------ src/widgets/glances/metrics/sensor.jsx | 7 +------ 11 files changed, 23 insertions(+), 72 deletions(-) diff --git a/src/widgets/glances/components/container.jsx b/src/widgets/glances/components/container.jsx index 8a72a1b316e..920fb71b1f2 100644 --- a/src/widgets/glances/components/container.jsx +++ b/src/widgets/glances/components/container.jsx @@ -1,10 +1,20 @@ -export default function Container({ children, chart = true, className = "" }) { +import { useContext } from "react"; + +import Error from "./error"; + +import { SettingsContext } from "utils/contexts/settings"; + +export default function Container({ children, widget, error = null, chart = true, className = "" }) { + const { settings } = useContext(SettingsContext); + const hideErrors = settings.hideErrors || widget?.hideErrors; + return (
{children}
{chart &&
} {!chart &&
} + {error && !hideErrors && }
); } diff --git a/src/widgets/glances/components/error.jsx b/src/widgets/glances/components/error.jsx index 1ee1ebcb324..d88a17c0ea5 100644 --- a/src/widgets/glances/components/error.jsx +++ b/src/widgets/glances/components/error.jsx @@ -1,17 +1,7 @@ import { useTranslation } from "next-i18next"; -import { useContext } from "react"; -import { SettingsContext } from "utils/contexts/settings"; - -export default function Error({ service, error }) { +export default function Error() { const { t } = useTranslation(); - const { settings } = useContext(SettingsContext); - - if (error) { - if (settings.hideErrors || service?.widget.hide_errors) { - return null; - } - return
{t("widget.api_error")}
; - } + return
{t("widget.api_error")}
; } diff --git a/src/widgets/glances/metrics/cpu.jsx b/src/widgets/glances/metrics/cpu.jsx index 9c5bf6e61cf..e993fca91b1 100644 --- a/src/widgets/glances/metrics/cpu.jsx +++ b/src/widgets/glances/metrics/cpu.jsx @@ -4,7 +4,6 @@ import { useTranslation } from "next-i18next"; import Container from "../components/container"; import Block from "../components/block"; -import Error from "../components/error"; import useWidgetAPI from "utils/proxy/use-widget-api"; @@ -39,11 +38,7 @@ export default function Component({ service }) { }, [data, pointsLimit]); if (error) { - return ( - - - - ); + return ; } if (!data) { diff --git a/src/widgets/glances/metrics/disk.jsx b/src/widgets/glances/metrics/disk.jsx index b2764eb4838..0a459e07cdb 100644 --- a/src/widgets/glances/metrics/disk.jsx +++ b/src/widgets/glances/metrics/disk.jsx @@ -2,7 +2,6 @@ import dynamic from "next/dynamic"; import { useState, useEffect } from "react"; import { useTranslation } from "next-i18next"; -import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -54,11 +53,7 @@ export default function Component({ service }) { if (error || (data && data.error)) { const finalError = error || data.error; - return ( - - - - ); + return ; } if (!data) { diff --git a/src/widgets/glances/metrics/fs.jsx b/src/widgets/glances/metrics/fs.jsx index ea7de8a0a2d..1fae5800490 100644 --- a/src/widgets/glances/metrics/fs.jsx +++ b/src/widgets/glances/metrics/fs.jsx @@ -1,6 +1,5 @@ import { useTranslation } from "next-i18next"; -import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -20,11 +19,7 @@ export default function Component({ service }) { }); if (error) { - return ( - - - - ); + return ; } if (!data) { diff --git a/src/widgets/glances/metrics/gpu.jsx b/src/widgets/glances/metrics/gpu.jsx index 158d03fde6f..37b06ce3eb2 100644 --- a/src/widgets/glances/metrics/gpu.jsx +++ b/src/widgets/glances/metrics/gpu.jsx @@ -2,7 +2,6 @@ import dynamic from "next/dynamic"; import { useState, useEffect } from "react"; import { useTranslation } from "next-i18next"; -import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -44,11 +43,7 @@ export default function Component({ service }) { if (error || (data && data.error)) { const finalError = error || data.error; - return ( - - - - ); + return ; } if (!data) { diff --git a/src/widgets/glances/metrics/info.jsx b/src/widgets/glances/metrics/info.jsx index ee19716aceb..3a4b565f4cd 100644 --- a/src/widgets/glances/metrics/info.jsx +++ b/src/widgets/glances/metrics/info.jsx @@ -1,6 +1,5 @@ import { useTranslation } from "next-i18next"; -import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -86,19 +85,11 @@ export default function Component({ service }) { if (quicklookError || (quicklookData && quicklookData.error)) { const qlError = quicklookError || quicklookData.error; - return ( - - - - ); + return ; } if (systemError) { - return ( - - - - ); + return ; } const dataCharts = []; diff --git a/src/widgets/glances/metrics/memory.jsx b/src/widgets/glances/metrics/memory.jsx index 87782120069..8cfddb668d8 100644 --- a/src/widgets/glances/metrics/memory.jsx +++ b/src/widgets/glances/metrics/memory.jsx @@ -2,7 +2,6 @@ import dynamic from "next/dynamic"; import { useState, useEffect } from "react"; import { useTranslation } from "next-i18next"; -import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -38,11 +37,7 @@ export default function Component({ service }) { }, [data, pointsLimit]); if (error) { - return ( - - - - ); + return ; } if (!data) { diff --git a/src/widgets/glances/metrics/net.jsx b/src/widgets/glances/metrics/net.jsx index 1ab49220777..372c4ec6197 100644 --- a/src/widgets/glances/metrics/net.jsx +++ b/src/widgets/glances/metrics/net.jsx @@ -2,7 +2,6 @@ import dynamic from "next/dynamic"; import { useState, useEffect } from "react"; import { useTranslation } from "next-i18next"; -import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -54,11 +53,7 @@ export default function Component({ service }) { if (error || (data && data.error)) { const finalError = error || data.error; - return ( - - - - ); + return ; } if (!data) { diff --git a/src/widgets/glances/metrics/process.jsx b/src/widgets/glances/metrics/process.jsx index b242535eebf..b997a568996 100644 --- a/src/widgets/glances/metrics/process.jsx +++ b/src/widgets/glances/metrics/process.jsx @@ -1,6 +1,5 @@ import { useTranslation } from "next-i18next"; -import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -31,11 +30,7 @@ export default function Component({ service }) { }); if (error) { - return ( - - - - ); + return ; } if (!data) { diff --git a/src/widgets/glances/metrics/sensor.jsx b/src/widgets/glances/metrics/sensor.jsx index 0b42e3d6426..f27afbadd46 100644 --- a/src/widgets/glances/metrics/sensor.jsx +++ b/src/widgets/glances/metrics/sensor.jsx @@ -2,7 +2,6 @@ import dynamic from "next/dynamic"; import { useState, useEffect } from "react"; import { useTranslation } from "next-i18next"; -import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -40,11 +39,7 @@ export default function Component({ service }) { if (error || (data && data.error)) { const finalError = error || data.error; - return ( - - - - ); + return ; } if (!data) { From b4a90fbf245804db334870cbdff70f7c2a5da255 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 22 Jun 2024 13:06:11 -0700 Subject: [PATCH 5/6] Update container.jsx --- src/widgets/glances/components/container.jsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/widgets/glances/components/container.jsx b/src/widgets/glances/components/container.jsx index 920fb71b1f2..ebbe3d986c0 100644 --- a/src/widgets/glances/components/container.jsx +++ b/src/widgets/glances/components/container.jsx @@ -8,13 +8,20 @@ export default function Container({ children, widget, error = null, chart = true const { settings } = useContext(SettingsContext); const hideErrors = settings.hideErrors || widget?.hideErrors; + if (error) { + if (hideErrors) { + return null; + } + + return ; + } + return (
{children}
{chart &&
} {!chart &&
} - {error && !hideErrors && }
); } From 56712e886ca55d7565e397662d0b80b8b148f64c Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 22 Jun 2024 13:11:17 -0700 Subject: [PATCH 6/6] One more error handling case --- src/widgets/glances/metrics/sensor.jsx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/widgets/glances/metrics/sensor.jsx b/src/widgets/glances/metrics/sensor.jsx index f27afbadd46..3cb38c1c65f 100644 --- a/src/widgets/glances/metrics/sensor.jsx +++ b/src/widgets/glances/metrics/sensor.jsx @@ -27,13 +27,17 @@ export default function Component({ service }) { useEffect(() => { if (data && !data.error) { const sensorData = data.find((item) => item.label === sensorName); - setDataPoints((prevDataPoints) => { - const newDataPoints = [...prevDataPoints, { value: sensorData.value }]; - if (newDataPoints.length > pointsLimit) { - newDataPoints.shift(); - } - return newDataPoints; - }); + if (sensorData) { + setDataPoints((prevDataPoints) => { + const newDataPoints = [...prevDataPoints, { value: sensorData.value }]; + if (newDataPoints.length > pointsLimit) { + newDataPoints.shift(); + } + return newDataPoints; + }); + } else { + data.error = true; + } } }, [data, sensorName, pointsLimit]);