diff --git a/src/lib/api/fetchRSS.ts b/src/lib/api/fetchRSS.ts index f191e3091bf..c97c8627939 100644 --- a/src/lib/api/fetchRSS.ts +++ b/src/lib/api/fetchRSS.ts @@ -19,6 +19,7 @@ export const fetchRSS = async (xmlUrl: string | string[]) => { const allItems: RSSItem[][] = [] for (const url of urls) { const response = (await fetchXml(url)) as RSSResult | AtomResult + if ("rss" in response) { const [mainChannel] = response.rss.channel as RSSChannel[] const [source] = mainChannel.title @@ -124,15 +125,19 @@ export const fetchRSS = async (xmlUrl: string | string[]) => { * @returns A promise that resolves to the parsed XML data as a JSON object. */ export const fetchXml = async (url: string) => { - const response = await fetch(url) - const xml = await response.text() - let returnObject: Record = {} - parseString(xml, (err, result) => { - if (err) { - console.error(err) - return - } - returnObject = result - }) - return returnObject + try { + const response = await fetch(url) + const xml = await response.text() + let returnObject: Record = {} + parseString(xml, (err, result) => { + if (err) { + throw err // Throw the error to be caught by the outer try-catch + } + returnObject = result + }) + return returnObject + } catch (error) { + console.error("Error fetching or parsing XML:", url, error) + throw error + } }