From b342b3f11ef3a1d823c31d274488f9609365b8fb Mon Sep 17 00:00:00 2001 From: Manuel <30572287+manuel-rw@users.noreply.github.com> Date: Sun, 22 Jan 2023 00:01:05 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20Add=20error=20hanlding=20for=20c?= =?UTF-8?q?alendar=20apps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/api/modules/calendar.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pages/api/modules/calendar.ts b/src/pages/api/modules/calendar.ts index daf9ec41a..d454497a9 100644 --- a/src/pages/api/modules/calendar.ts +++ b/src/pages/api/modules/calendar.ts @@ -54,6 +54,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) { return { type: integration.type, items: [], + success: false, }; } @@ -67,15 +68,30 @@ async function Get(req: NextApiRequest, res: NextApiResponse) { const end = new Date(year, month, 0); // Last day of month const apiKey = integration.properties.find((x) => x.field === 'apiKey')?.value; - if (!apiKey) return { type: integration.type, items: [] }; + if (!apiKey) return { type: integration.type, items: [], success: false }; return axios .get( `${origin}${endpoint}?apiKey=${apiKey}&end=${end.toISOString()}&start=${start.toISOString()}` ) - .then((x) => ({ type: integration.type, items: x.data as any[] })); + .then((x) => ({ type: integration.type, items: x.data as any[], success: true })) + .catch((err) => { + Consola.error( + `failed to process request to app '${integration.type}' (${app.id}): ${err}` + ); + return { + type: integration.type, + items: [], + success: false, + }; + }); }) ); + const countFailed = medias.filter(x => !x.success).length; + if (countFailed > 0) { + Consola.warn(`A total of ${countFailed} apps for the calendar widget failed`); + } + return res.status(200).json({ tvShows: medias.filter((m) => m.type === 'sonarr').flatMap((m) => m.items), movies: medias.filter((m) => m.type === 'radarr').flatMap((m) => m.items),