🐛 DNS-Hole error handling and fixes (#1419)
* 🐛 Remove url requirement * ⚡️ Ignore dnshole in widget when not contactable * ✨ Error tile for dns-control instead of load loop
This commit is contained in:
@@ -7,6 +7,12 @@
|
|||||||
"showToggleAllButtons": {
|
"showToggleAllButtons": {
|
||||||
"label": "Show 'Enable/Disable All' Buttons"
|
"label": "Show 'Enable/Disable All' Buttons"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"errors": {
|
||||||
|
"general": {
|
||||||
|
"title": "Unable to find a DNS hole",
|
||||||
|
"text": "There was a problem connecting to your DNS Hole(s). Please verify your configuration/integration(s)."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,22 +62,24 @@ export const dnsHoleRouter = createTRPCRouter({
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const data = result.reduce(
|
const data = result
|
||||||
(prev: AdStatistics, curr) => ({
|
.filter((x) => x !== null)
|
||||||
domainsBeingBlocked: prev.domainsBeingBlocked + curr.domainsBeingBlocked,
|
.reduce(
|
||||||
adsBlockedToday: prev.adsBlockedToday + curr.adsBlockedToday,
|
(prev: AdStatistics, curr) => ({
|
||||||
dnsQueriesToday: prev.dnsQueriesToday + curr.dnsQueriesToday,
|
domainsBeingBlocked: prev.domainsBeingBlocked + curr!.domainsBeingBlocked,
|
||||||
status: [...prev.status, curr.status],
|
adsBlockedToday: prev.adsBlockedToday + curr!.adsBlockedToday,
|
||||||
adsBlockedTodayPercentage: 0,
|
dnsQueriesToday: prev.dnsQueriesToday + curr!.dnsQueriesToday,
|
||||||
}),
|
status: [...prev.status, curr!.status],
|
||||||
{
|
adsBlockedTodayPercentage: 0,
|
||||||
domainsBeingBlocked: 0,
|
}),
|
||||||
adsBlockedToday: 0,
|
{
|
||||||
adsBlockedTodayPercentage: 0,
|
domainsBeingBlocked: 0,
|
||||||
dnsQueriesToday: 0,
|
adsBlockedToday: 0,
|
||||||
status: [],
|
adsBlockedTodayPercentage: 0,
|
||||||
}
|
dnsQueriesToday: 0,
|
||||||
);
|
status: [],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
data.adsBlockedTodayPercentage = data.adsBlockedToday / data.dnsQueriesToday;
|
data.adsBlockedTodayPercentage = data.adsBlockedToday / data.dnsQueriesToday;
|
||||||
if (Number.isNaN(data.adsBlockedTodayPercentage)) {
|
if (Number.isNaN(data.adsBlockedTodayPercentage)) {
|
||||||
@@ -131,7 +133,13 @@ const processPiHole = async (app: ConfigAppType, enable: boolean) => {
|
|||||||
|
|
||||||
const collectPiHoleSummary = async (app: ConfigAppType) => {
|
const collectPiHoleSummary = async (app: ConfigAppType) => {
|
||||||
const piHole = new PiHoleClient(app.url, findAppProperty(app, 'apiKey'));
|
const piHole = new PiHoleClient(app.url, findAppProperty(app, 'apiKey'));
|
||||||
const summary = await piHole.getSummary();
|
const summary = await piHole.getSummary().catch(() => {
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!summary) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
domainsBeingBlocked: summary.domains_being_blocked,
|
domainsBeingBlocked: summary.domains_being_blocked,
|
||||||
@@ -152,7 +160,14 @@ const collectAdGuardSummary = async (app: ConfigAppType) => {
|
|||||||
findAppProperty(app, 'password')
|
findAppProperty(app, 'password')
|
||||||
);
|
);
|
||||||
|
|
||||||
const stats = await adGuard.getStats();
|
const stats = await adGuard.getStats().catch(() => {
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!stats) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const status = await adGuard.getStatus();
|
const status = await adGuard.getStatus();
|
||||||
const countFilteredDomains = await adGuard.getCountFilteringDomains();
|
const countFilteredDomains = await adGuard.getCountFilteringDomains();
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export const adGuardApiStatusResponseSchema = z.object({
|
|||||||
export const adGuardApiFilteringStatusSchema = z.object({
|
export const adGuardApiFilteringStatusSchema = z.object({
|
||||||
filters: z.array(
|
filters: z.array(
|
||||||
z.object({
|
z.object({
|
||||||
url: z.string().url(),
|
url: z.string(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
last_updated: z.string().optional(),
|
last_updated: z.string().optional(),
|
||||||
id: z.number().nonnegative(),
|
id: z.number().nonnegative(),
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ import {
|
|||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
|
Center,
|
||||||
Group,
|
Group,
|
||||||
Image,
|
Image,
|
||||||
SimpleGrid,
|
SimpleGrid,
|
||||||
Stack,
|
Stack,
|
||||||
Text,
|
Text,
|
||||||
|
Title,
|
||||||
UnstyledButton,
|
UnstyledButton,
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { useElementSize } from '@mantine/hooks';
|
import { useElementSize } from '@mantine/hooks';
|
||||||
@@ -71,7 +73,7 @@ function DnsHoleControlsWidgetTile({ widget }: DnsHoleControlsWidgetProps) {
|
|||||||
const { isInitialLoading, data, isFetching: fetchingDnsSummary } = useDnsHoleSummeryQuery();
|
const { isInitialLoading, data, isFetching: fetchingDnsSummary } = useDnsHoleSummeryQuery();
|
||||||
const { mutateAsync, isLoading: changingStatus } = useDnsHoleControlMutation();
|
const { mutateAsync, isLoading: changingStatus } = useDnsHoleControlMutation();
|
||||||
const { width, ref } = useElementSize();
|
const { width, ref } = useElementSize();
|
||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation(['common', 'modules/dns-hole-controls']);
|
||||||
|
|
||||||
const { name: configName, config } = useConfigContext();
|
const { name: configName, config } = useConfigContext();
|
||||||
|
|
||||||
@@ -81,6 +83,20 @@ function DnsHoleControlsWidgetTile({ widget }: DnsHoleControlsWidgetProps) {
|
|||||||
return <WidgetLoading />;
|
return <WidgetLoading />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.status.length === 0) {
|
||||||
|
return(
|
||||||
|
<Center h="100%">
|
||||||
|
<Stack align="center">
|
||||||
|
<IconDeviceGamepad size={40} strokeWidth={1}/>
|
||||||
|
<Title align="center" order={6}>{t('modules/dns-hole-controls:descriptor.errors.general.title')}</Title>
|
||||||
|
<Text align="center">{t('modules/dns-hole-controls:descriptor.errors.general.text')}</Text>
|
||||||
|
</Stack>
|
||||||
|
</Center>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
type getDnsStatusAcc = {
|
type getDnsStatusAcc = {
|
||||||
enabled: string[];
|
enabled: string[];
|
||||||
disabled: string[];
|
disabled: string[];
|
||||||
|
|||||||
Reference in New Issue
Block a user