File tree Expand file tree Collapse file tree 1 file changed +16
-11
lines changed Expand file tree Collapse file tree 1 file changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ export const fetchRSS = async (xmlUrl: string | string[]) => {
19
19
const allItems : RSSItem [ ] [ ] = [ ]
20
20
for ( const url of urls ) {
21
21
const response = ( await fetchXml ( url ) ) as RSSResult | AtomResult
22
+
22
23
if ( "rss" in response ) {
23
24
const [ mainChannel ] = response . rss . channel as RSSChannel [ ]
24
25
const [ source ] = mainChannel . title
@@ -124,15 +125,19 @@ export const fetchRSS = async (xmlUrl: string | string[]) => {
124
125
* @returns A promise that resolves to the parsed XML data as a JSON object.
125
126
*/
126
127
export const fetchXml = async ( url : string ) => {
127
- const response = await fetch ( url )
128
- const xml = await response . text ( )
129
- let returnObject : Record < string , unknown > = { }
130
- parseString ( xml , ( err , result ) => {
131
- if ( err ) {
132
- console . error ( err )
133
- return
134
- }
135
- returnObject = result
136
- } )
137
- return returnObject
128
+ try {
129
+ const response = await fetch ( url )
130
+ const xml = await response . text ( )
131
+ let returnObject : Record < string , unknown > = { }
132
+ parseString ( xml , ( err , result ) => {
133
+ if ( err ) {
134
+ throw err // Throw the error to be caught by the outer try-catch
135
+ }
136
+ returnObject = result
137
+ } )
138
+ return returnObject
139
+ } catch ( error ) {
140
+ console . error ( "Error fetching or parsing XML:" , url , error )
141
+ throw error
142
+ }
138
143
}
You can’t perform that action at this time.
0 commit comments