From f5fef7b623639399e81b284f56f9e85454cc76c2 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 18 Apr 2026 09:01:52 +0000 Subject: fix(media): guard publicMediaListCollection against missing AniList data The public variant of mediaListCollection chained data.MediaListCollection .lists with no null check, so any AniList error response (rate limit, private list, nonexistent user) threw a TypeError. Mirror the guard used by the authenticated sibling: if any of data, MediaListCollection, or lists is missing, return an empty array. The function currently has no in-tree callers; noting that it may be a candidate for removal in a follow-up. --- src/lib/Data/AniList/media.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/lib/Data/AniList/media.ts b/src/lib/Data/AniList/media.ts index 099d4182..b9e0ef3f 100644 --- a/src/lib/Data/AniList/media.ts +++ b/src/lib/Data/AniList/media.ts @@ -429,23 +429,24 @@ export const mediaListCollection = async ( export const publicMediaListCollection = async ( userId: number, type: Type, -): Promise => - flattenLists( - ( - await ( - await fetch("https://graphql.anilist.co", { - method: "POST", - headers: { - "Content-Type": "application/json", - Accept: "application/json", - }, - body: JSON.stringify({ - query: collectionQueryTemplate(type, userId, {}), - }), - }) - ).json() - )["data"]["MediaListCollection"]["lists"], - ); +): Promise => { + const response = await ( + await fetch("https://graphql.anilist.co", { + method: "POST", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + }, + body: JSON.stringify({ + query: collectionQueryTemplate(type, userId, {}), + }), + }) + ).json(); + + if (!response?.data?.MediaListCollection?.lists) return []; + + return flattenLists(response.data.MediaListCollection.lists); +}; const countMedian = (guesses: number[]) => { guesses.sort((a: number, b: number) => a - b); -- cgit v1.2.3