mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 23:45:48 +01:00
🥅 Add error hanlding for calendar apps
This commit is contained in:
@@ -54,6 +54,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
return {
|
return {
|
||||||
type: integration.type,
|
type: integration.type,
|
||||||
items: [],
|
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 end = new Date(year, month, 0); // Last day of month
|
||||||
|
|
||||||
const apiKey = integration.properties.find((x) => x.field === 'apiKey')?.value;
|
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
|
return axios
|
||||||
.get(
|
.get(
|
||||||
`${origin}${endpoint}?apiKey=${apiKey}&end=${end.toISOString()}&start=${start.toISOString()}`
|
`${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({
|
return res.status(200).json({
|
||||||
tvShows: medias.filter((m) => m.type === 'sonarr').flatMap((m) => m.items),
|
tvShows: medias.filter((m) => m.type === 'sonarr').flatMap((m) => m.items),
|
||||||
movies: medias.filter((m) => m.type === 'radarr').flatMap((m) => m.items),
|
movies: medias.filter((m) => m.type === 'radarr').flatMap((m) => m.items),
|
||||||
|
|||||||
Reference in New Issue
Block a user