Skip to content

Commit 0a7e55b

Browse files
committed
fix: error logging
Pass individual fetch/parse errors from child process and console.warn with parent, continuing processes. Add additional guard to make sure enough blog items were fetch; if less then break build.
1 parent 02da378 commit 0a7e55b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/lib/api/fetchRSS.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { parseString } from "xml2js"
22

3+
import { RSS_DISPLAY_COUNT } from "../constants"
34
import type { AtomElement, AtomResult, RSSItem, RSSResult } from "../types"
45
import { isValidDate } from "../utils/date"
56

@@ -116,13 +117,14 @@ export const fetchRSS = async (xmlUrl: string | string[]) => {
116117
allItems.push(parsedAtomItems)
117118
}
118119
} catch (error) {
119-
console.error(
120-
`Failed to fetch or parse RSS feed from ${url}:`,
121-
error instanceof Error ? error.message : error
122-
)
120+
console.error(error instanceof Error ? error.message : error)
123121
continue
124122
}
125123
}
124+
125+
if (allItems.length < RSS_DISPLAY_COUNT)
126+
throw new Error("Insufficient number of RSS items fetched")
127+
126128
return allItems
127129
}
128130

@@ -142,7 +144,6 @@ export const fetchXml = async (url: string) => {
142144
})
143145
})
144146
} catch (error) {
145-
console.error("Error fetching or parsing XML:", url, error)
146-
throw error
147+
throw new Error(`Error fetching or parsing XML: ${url}`)
147148
}
148149
}

0 commit comments

Comments
 (0)