🐛 Add error catching for calender api route

This commit is contained in:
Manuel Ruwe
2023-01-10 20:55:35 +01:00
parent 4513aa66f0
commit bbf1255b8b
4 changed files with 49 additions and 36 deletions

View File

@@ -3,6 +3,7 @@
"name": "Calendar",
"description": "A calendar module for displaying upcoming releases. It interacts with the Sonarr and Radarr API.",
"settings": {
"title": "Settings for calendar integration",
"sundayStart": {
"label": "Start the week on Sunday"
}

View File

@@ -26,6 +26,5 @@
}
},
"tip": "You can select the search bar with the shortcut ",
"switchedSearchEngine": "Switched to searching with {{searchEngine}}",
"configurationName": "Search engine configuration"
"switchedSearchEngine": "Switched to searching with {{searchEngine}}"
}

View File

@@ -1,5 +1,6 @@
{
"title": "Search engine",
"configurationName": "Search engine configuration",
"tips": {
"generalTip": "Use the prefixes !yt and !t in front of your query to search on YouTube or for a Torrent respectively.",
"placeholderTip": "%s can be used as a placeholder for the query."

View File

@@ -1,4 +1,5 @@
import axios from 'axios';
import Consola from 'consola';
import { NextApiRequest, NextApiResponse } from 'next';
import { getConfig } from '../../../tools/config/getConfig';
import { AppIntegrationType } from '../../../types/app';
@@ -44,6 +45,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
(app) => app.integration && mediaAppIntegrationTypes.includes(app.integration.type)
);
try {
const medias = await Promise.all(
await mediaApps.map(async (app) => {
const integration = app.integration!;
@@ -74,7 +76,6 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
})
);
// FIXME: I need an integration for each of them
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),
@@ -82,6 +83,17 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
musics: medias.filter((m) => m.type === 'lidarr').flatMap((m) => m.items),
totalCount: medias.reduce((p, c) => p + c.items.length, 0),
});
} catch (error) {
Consola.error(`Error while requesting media from your app. Check your configuration. ${error}`);
return res.status(500).json({
tvShows: [],
movies: [],
books: [],
musics: [],
totalCount: 0,
});
}
}
const IntegrationTypeEndpointMap = new Map<AppIntegrationType['type'], string>([