Skip to content

Commit e9f2f44

Browse files
authored
fix(api): catch error when watchlist item doesn't exist anymore (#1907)
1 parent d5bf175 commit e9f2f44

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

server/api/plextv.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,25 @@ class PlexTvAPI extends ExternalAPI {
312312
const watchlistDetails = await Promise.all(
313313
(cachedWatchlist?.response.MediaContainer.Metadata ?? []).map(
314314
async (watchlistItem) => {
315-
const detailedResponse = await this.getRolling<MetadataResponse>(
316-
`/library/metadata/${watchlistItem.ratingKey}`,
317-
{
318-
baseURL: 'https://discover.provider.plex.tv',
315+
let detailedResponse: MetadataResponse;
316+
try {
317+
detailedResponse = await this.getRolling<MetadataResponse>(
318+
`/library/metadata/${watchlistItem.ratingKey}`,
319+
{
320+
baseURL: 'https://discover.provider.plex.tv',
321+
}
322+
);
323+
} catch (e) {
324+
if (e.response?.status === 404) {
325+
logger.warn(
326+
`Item with ratingKey ${watchlistItem.ratingKey} not found, it may have been removed from the server.`,
327+
{ label: 'Plex.TV Metadata API' }
328+
);
329+
return null;
330+
} else {
331+
throw e;
319332
}
320-
);
333+
}
321334

322335
const metadata = detailedResponse.MediaContainer.Metadata[0];
323336

@@ -343,7 +356,9 @@ class PlexTvAPI extends ExternalAPI {
343356
)
344357
);
345358

346-
const filteredList = watchlistDetails.filter((detail) => detail.tmdbId);
359+
const filteredList = watchlistDetails.filter(
360+
(detail) => detail?.tmdbId
361+
) as PlexWatchlistItem[];
347362

348363
return {
349364
offset,

0 commit comments

Comments
 (0)