Add detailed Error component for service widgets

pull/502/head
Michael Shamoon 2 years ago
parent 7b7740563e
commit 21017e4716

@ -1,10 +1,8 @@
import Error from "./error";
export default function Container({ error = false, children, service }) {
if (error) {
return (
<div className="bg-theme-200/50 dark:bg-theme-900/20 rounded m-1 flex-1 flex flex-col items-center justify-center p-1">
<div className="font-thin text-sm">{error}</div>
</div>
);
return <Error error={error} />
}
let visibleChildren = children;

@ -11,10 +11,10 @@ export default function Component({ service }) {
const { data: adguardData, error: adguardError } = useWidgetAPI(widget, "stats");
if (adguardError) {
return <Container error={t("widget.api_error")} />;
if (adguardError || adguardData?.error) {
const finalError = adguardError ?? adguardData.error;
return <Container error={finalError} />;
}
if (!adguardData) {
return (
<Container service={service}>

@ -13,8 +13,9 @@ export default function Component({ service }) {
const { data: loginsData, error: loginsError } = useWidgetAPI(widget, "login");
const { data: failedLoginsData, error: failedLoginsError } = useWidgetAPI(widget, "login_failed");
if (usersError || loginsError || failedLoginsError) {
return <Container error={t("widget.api_error")} />;
if (usersError || usersData?.error || loginsError || loginsData?.error || failedLoginsError || failedLoginsData?.error) {
const finalError = usersError ?? usersData?.error ?? loginsError ?? loginsData?.error ?? failedLoginsError ?? failedLoginsData?.error;
return <Container error={finalError} />;
}
if (!usersData || !loginsData || !failedLoginsData) {

@ -12,8 +12,9 @@ export default function Component({ service }) {
const { data: episodesData, error: episodesError } = useWidgetAPI(widget, "episodes");
const { data: moviesData, error: moviesError } = useWidgetAPI(widget, "movies");
if (episodesError || moviesError) {
return <Container error="widget.api_error" />;
if (moviesError || moviesData?.error || episodesError || episodesData?.error) {
const finalError = moviesError ?? moviesData?.error ?? episodesError ?? episodesData?.error;
return <Container error={finalError} />;
}
if (!episodesData || !moviesData) {

@ -9,12 +9,12 @@ export default function Component({ service }) {
const { widget } = service;
const { data } = useWidgetAPI(widget, "info");
const { data, error } = useWidgetAPI(widget, "info");
if (!data) {
return <Container error="widget.api_error" />;
if (error || data?.error) {
const finalError = error ?? data.error;
return <Container error={finalError} />;
}
const totalObserved = Object.keys(data).length;
let diffsDetected = 0;

@ -36,8 +36,9 @@ export default function Component({ service }) {
);
}
if (statsError) {
return <Container error={t("widget.api_error")} />;
if (statsError || statsData?.error) {
const finalError = statsError ?? statsData.error;
return <Container error={finalError} />;
}
if (!statsData || !dateRange) {

@ -17,8 +17,9 @@ export default function Component({ service }) {
const { data: statsData, error: statsError } = useSWR(`/api/docker/stats/${widget.container}/${widget.server || ""}`);
if (statsError || statusError) {
return <Container error={t("widget.api_error")} />;
if (statsError || statsData?.error || statusError || statusData?.error) {
const finalError = statsError ?? statsData?.error ?? statusError ?? statusData?.error;
return <Container error={finalError} />;
}
if (statusData && statusData.status !== "running") {

@ -3,8 +3,8 @@ import { useTranslation } from "next-i18next";
import { BsVolumeMuteFill, BsFillPlayFill, BsPauseFill, BsCpu, BsFillCpuFill } from "react-icons/bs";
import { MdOutlineSmartDisplay } from "react-icons/md";
import Container from "components/services/widget/container";
import { formatProxyUrl, formatProxyUrlWithSegments } from "utils/proxy/api-helpers";
import Container from "components/services/widget/container";
function ticksToTime(ticks) {
const milliseconds = ticks / 10000;
@ -172,7 +172,8 @@ export default function Component({ service }) {
}
if (sessionsError || sessionsData?.error) {
return <Container error={t("widget.api_error")} />;
const finalError = sessionsError ?? sessionsData.error;
return <Container error={finalError} />;
}
if (!sessionsData) {

@ -1,20 +1,17 @@
import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: appsData, error: appsError } = useWidgetAPI(widget, "application");
const { data: messagesData, error: messagesError } = useWidgetAPI(widget, "message");
const { data: clientsData, error: clientsError } = useWidgetAPI(widget, "client");
if (appsError || messagesError || clientsError) {
return <Container error={t("widget.api_error")} />;
if (appsError || appsData?.error || messagesError || messagesData?.error || clientsError || clientsData?.error) {
const finalError = appsError ?? appsData?.error ?? messagesError ?? messagesData?.error ?? clientsError ?? clientsData?.error;
return <Container error={finalError} />;
}

@ -11,8 +11,9 @@ export default function Component({ service }) {
const { data: indexersData, error: indexersError } = useWidgetAPI(widget, "indexers");
if (indexersError) {
return <Container error={t("widget.api_error")} />;
if (indexersError || indexersData?.error) {
const finalError = indexersError ?? indexersData.error;
return <Container error={finalError} />;
}
if (!indexersData) {

@ -1,18 +1,15 @@
import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: statsData, error: statsError } = useWidgetAPI(widget, "request/count");
if (statsError) {
return <Container error={t("widget.api_error")} />;
if (statsError || statsData?.error) {
const finalError = statsError ?? statsData.error;
return <Container error={finalError} />;
}
if (!statsData) {

@ -13,8 +13,9 @@ export default function Component({ service }) {
const { data: wantedData, error: wantedError } = useWidgetAPI(widget, "wanted/missing");
const { data: queueData, error: queueError } = useWidgetAPI(widget, "queue/status");
if (albumsError || wantedError || queueError) {
return <Container error={t("widget.api_error")} />;
if (albumsError || albumsData?.error || wantedError || wantedData?.error || queueError || queueData?.error) {
const finalError = albumsError ?? albumsData?.error ?? wantedError ?? wantedData?.error ?? queueError ?? queueData?.error;
return <Container error={finalError} />;
}
if (!albumsData || !wantedData || !queueData) {

@ -11,8 +11,9 @@ export default function Component({ service }) {
const { data: statsData, error: statsError } = useWidgetAPI(widget, "instance");
if (statsError) {
return <Container error={t("widget.api_error")} />;
if (statsError || statsData?.error) {
const finalError = statsError ?? statsData.error;
return <Container error={finalError} />;
}
if (!statsData) {

@ -1,18 +1,14 @@
import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: infoData, error: infoError } = useWidgetAPI(widget, "nginx/proxy-hosts");
if (infoError || infoData?.error) {
return <Container error={t("widget.api_error")} />;
if (infoError) {
return <Container error={infoError} />;
}
if (!infoData) {

@ -11,8 +11,9 @@ export default function Component({ service }) {
const { data: statusData, error: statusError } = useWidgetAPI(widget, "status");
if (statusError) {
return <Container error={t("widget.api_error")} />;
if (statusError || statusData?.error) {
const finalError = statusError ?? statusData.error;
return <Container error={finalError} />;
}
if (!statusData) {

@ -1,18 +1,15 @@
import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: statsData, error: statsError } = useWidgetAPI(widget, "Request/count");
if (statsError) {
return <Container error={t("widget.api_error")} />;
if (statsError || statsData?.error) {
const finalError = statsError ?? statsData.error;
return <Container error={finalError} />;
}
if (!statsData) {

@ -1,18 +1,15 @@
import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: statsData, error: statsError } = useWidgetAPI(widget, "request/count");
if (statsError) {
return <Container error={t("widget.api_error")} />;
if (statsError || statsData?.error) {
const finalError = statsError ?? statsData.error;
return <Container error={finalError} />;
}
if (!statsData) {

@ -11,8 +11,9 @@ export default function Component({ service }) {
const { data: piholeData, error: piholeError } = useWidgetAPI(widget, "api.php");
if (piholeError) {
return <Container error={t("widget.api_error")} />;
if (piholeError || piholeData?.error) {
const finalError = piholeError ?? piholeData.error;
return <Container error={finalError} />;
}
if (!piholeData) {

@ -14,8 +14,9 @@ export default function Component({ service }) {
refreshInterval: 5000,
});
if (plexAPIError) {
return <Container error={t("widget.api_error")} />;
if (plexAPIError || plexData?.error) {
const finalError = plexAPIError ?? plexData.error;
return <Container error={finalError} />;
}
if (!plexData) {

@ -44,7 +44,7 @@ async function fetchFromPlexAPI(endpoint, widget) {
if (status !== 200) {
logger.error("HTTP %d communicating with Plex. Data: %s", status, data.toString());
return [status, data.toString()];
return [status, data];
}
try {
@ -65,6 +65,11 @@ export default async function plexProxyHandler(req, res) {
logger.debug("Getting streams from Plex API");
let streams;
let [status, apiData] = await fetchFromPlexAPI("/status/sessions", widget);
if (status !== 200) {
return res.status(status).json({error: {message: "HTTP error communicating with Plex API", data: apiData}});
}
if (apiData && apiData.MediaContainer) {
streams = apiData.MediaContainer._attributes.size;
}

@ -13,8 +13,9 @@ export default function Component({ service }) {
all: 1,
});
if (containersError) {
return <Container error={t("widget.api_error")} />;
if (containersError || containersData?.error) {
const finalError = containersError ?? containersData.error;
return <Container error={finalError} />;
}
if (!containersData) {

@ -1,19 +1,16 @@
import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: indexersData, error: indexersError } = useWidgetAPI(widget, "indexer");
const { data: grabsData, error: grabsError } = useWidgetAPI(widget, "indexerstats");
if (indexersError || grabsError) {
return <Container error={t("widget.api_error")} />;
if (indexersError || indexersData?.error || grabsError || grabsData?.error) {
const finalError = indexersError ?? indexersData?.error ?? grabsError ?? grabsData?.error;
return <Container error={finalError} />;
}
if (!indexersData || !grabsData) {

@ -15,8 +15,9 @@ export default function Component({ service }) {
const { data: clusterData, error: clusterError } = useWidgetAPI(widget, "cluster/resources");
if (clusterError) {
return <Container error={t("widget.api_error")} />;
if (clusterError || clusterData?.error) {
const finalError = clusterError ?? clusterData.error;
return <Container error={finalError} />;
}
if (!clusterData || !clusterData.data) {

@ -11,8 +11,9 @@ export default function Component({ service }) {
const { data: torrentData, error: torrentError } = useWidgetAPI(widget, "torrents/info");
if (torrentError) {
return <Container error={t("widget.api_error")} />;
if (torrentError || torrentData?.error) {
const finalError = torrentError ?? torrentData.error;
return <Container error={finalError} />;
}
if (!torrentData) {

@ -1,19 +1,16 @@
import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: moviesData, error: moviesError } = useWidgetAPI(widget, "movie");
const { data: queuedData, error: queuedError } = useWidgetAPI(widget, "queue/status");
if (moviesError || queuedError) {
return <Container error={t("widget.api_error")} />;
if (moviesError || moviesData?.error || queuedError || queuedData?.error) {
const finalError = moviesError ?? moviesData?.error ?? queuedError ?? queuedData?.error;
return <Container error={finalError} />;
}
if (!moviesData || !queuedData) {

@ -13,8 +13,9 @@ export default function Component({ service }) {
const { data: wantedData, error: wantedError } = useWidgetAPI(widget, "wanted/missing");
const { data: queueData, error: queueError } = useWidgetAPI(widget, "queue/status");
if (booksError || wantedError || queueError) {
return <Container error={t("widget.api_error")} />;
if (booksError || booksData?.error || wantedError || wantedData?.error || queueError || queueData?.error) {
const finalError = booksError ?? booksData?.error ?? wantedError ?? wantedData?.error ?? queueError ?? queueData?.error;
return <Container error={finalError} />;
}
if (!booksData || !wantedData || !queueData) {

@ -11,8 +11,9 @@ export default function Component({ service }) {
const { data: statusData, error: statusError } = useWidgetAPI(widget);
if (statusError) {
return <Container error={t("widget.api_error")} />;
if (statusError || statusData?.error) {
const finalError = statusError ?? statusData.error;
return <Container error={finalError} />;
}
if (!statusData) {

@ -21,8 +21,9 @@ export default function Component({ service }) {
const { data: queueData, error: queueError } = useWidgetAPI(widget, "queue");
if (queueError) {
return <Container error={t("widget.api_error")} />;
if (queueError || queueData?.error) {
const finalError = queueError ?? queueData.error;
return <Container error={finalError} />;
}
if (!queueData) {

@ -1,20 +1,17 @@
import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: wantedData, error: wantedError } = useWidgetAPI(widget, "wanted/missing");
const { data: queuedData, error: queuedError } = useWidgetAPI(widget, "queue");
const { data: seriesData, error: seriesError } = useWidgetAPI(widget, "series");
if (wantedError || queuedError || seriesError) {
return <Container error={t("widget.api_error")} />;
if (wantedError || wantedData?.error || queuedError || queuedData?.error || seriesError || seriesData?.error) {
const finalError = wantedError ?? wantedData?.error ?? queuedError ?? queuedData?.error ?? seriesError ?? seriesData?.error;
return <Container error={finalError} />;
}
if (!wantedData || !queuedData || !seriesData) {

@ -11,8 +11,9 @@ export default function Component({ service }) {
const { data: speedtestData, error: speedtestError } = useWidgetAPI(widget, "speedtest/latest");
if (speedtestError || (speedtestData && !speedtestData.data)) {
return <Container error={t("widget.api_error")} />;
if (speedtestError || speedtestData?.error) {
const finalError = speedtestError ?? speedtestData.error;
return <Container error={finalError} />;
}
if (!speedtestData) {

@ -11,8 +11,9 @@ export default function Component({ service }) {
const { data: statsData, error: statsError } = useWidgetAPI(widget, "status");
if (statsError) {
return <Container error={t("widget.api_error")} />;
if (statsError || statsData?.error) {
const finalError = statsError ?? statsData.error;
return <Container error={finalError} />;
}
if (!statsData) {

@ -4,8 +4,8 @@ import { useTranslation } from "next-i18next";
import { BsFillPlayFill, BsPauseFill, BsCpu, BsFillCpuFill } from "react-icons/bs";
import { MdOutlineSmartDisplay, MdSmartDisplay } from "react-icons/md";
import Container from "components/services/widget/container";
import { formatProxyUrl } from "utils/proxy/api-helpers";
import Container from "components/services/widget/container";
function millisecondsToTime(milliseconds) {
const seconds = Math.floor((milliseconds / 1000) % 60);
@ -123,8 +123,9 @@ export default function Component({ service }) {
refreshInterval: 5000,
});
if (activityError) {
return <Container error={t("widget.api_error")} />;
if (activityError || activityData?.error) {
const finalError = activityError ?? activityData.error;
return <Container error={finalError} />;
}
if (!activityData) {

@ -1,18 +1,15 @@
import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: traefikData, error: traefikError } = useWidgetAPI(widget, "overview");
if (traefikError) {
return <Container error={t("widget.api_error")} />;
if (traefikError || traefikData?.error) {
const finalError = traefikError ?? traefikData.error;
return <Container error={finalError} />;
}
if (!traefikData) {

@ -11,8 +11,9 @@ export default function Component({ service }) {
const { data: torrentData, error: torrentError } = useWidgetAPI(widget);
if (torrentError) {
return <Container error={t("widget.api_error")} />;
if (torrentError || torrentData?.error) {
const finalError = torrentError ?? torrentData.error;
return <Container error={finalError} />;
}
if (!torrentData) {

@ -68,6 +68,7 @@ export default async function transmissionProxyHandler(req, res) {
if (status !== 200) {
logger.error("Error getting data from Transmission: %d. Data: %s", status, data);
return res.status(500).send({error: {message:"Error getting data from Transmission", url, data}});
}
if (contentType) res.setHeader("Content-Type", contentType);

@ -12,7 +12,8 @@ export default function Component({ service }) {
const { data: statsData, error: statsError } = useWidgetAPI(widget, "stat/sites");
if (statsError || statsData?.error) {
return <Container error={t("widget.api_error")} />;
const finalError = statsError ?? statsData.error;
return <Container error={finalError} />;
}
const defaultSite = statsData?.data?.find(s => s.name === "default");

@ -74,7 +74,7 @@ export default async function unifiProxyHandler(req, res) {
// don't make two requests each time data from Unifi is required
[status, contentType, data, responseHeaders] = await httpProxy(widget.url);
prefix = "";
if (responseHeaders["x-csrf-token"]) {
if (responseHeaders?.["x-csrf-token"]) {
prefix = udmpPrefix;
}
cache.put(prefixCacheKey, prefix);
@ -88,13 +88,14 @@ export default async function unifiProxyHandler(req, res) {
setCookieHeader(url, params);
[status, contentType, data, responseHeaders] = await httpProxy(url, params);
if (status === 401) {
logger.debug("Unifi isn't logged in or rejected the reqeust, attempting login.");
[status, contentType, data, responseHeaders] = await login(widget);
if (status !== 200) {
logger.error("HTTP %d logging in to Unifi. Data: %s", status, data);
return res.status(status).end(data);
return res.status(status).json({error: {message: `HTTP Error ${status}`, url, data}});
}
const json = JSON.parse(data.toString());
@ -112,6 +113,7 @@ export default async function unifiProxyHandler(req, res) {
if (status !== 200) {
logger.error("HTTP %d getting data from Unifi endpoint %s. Data: %s", status, url.href, data);
return res.status(status).json({error: {message: `HTTP Error ${status}`, url, data}});
}
if (contentType) res.setHeader("Content-Type", contentType);

Loading…
Cancel
Save