danmactough / node-feedparser

Robust RSS, Atom, and RDF feed parsing in Node.js
Other
1.97k stars 192 forks source link

Unhandled "Not a feed" exception when a 200 response contains invalid data #254

Closed mitchdowney closed 6 years ago

mitchdowney commented 6 years ago

feedparser@2.2.7 node@8.4.0 Problem feeds: http://jerriwilliams.com/feed/podcast/ http://feeds.feedburner.com/JonoBen-TheRock

The feed URL above returns a 200 success response but an invalid feed. When I try to parse this URL, FeedParser gives me the following uncaught error:

Error: Not a feed
    at FeedParser.handleEnd (/Users/mitch/Repos/podcast-db/node_modules/feedparser/lib/feedparser/index.js:119:13)
    at emitNone (events.js:105:13)
    at SAXStream.emit (events.js:207:7)

Since the req.on('error') listener is never called, the app never has the chance to handle the error, and feedparser fails then stops running.

I tried setting resume_saxerror: false but I get the same result.

It turns out a valid feed URL can be found at http://jerriwilliams.com/feed/podcast, but ideally FeedParser doesn't crash completely whenever a URL returns a 200 response with invalid feed content.

Any ideas how we can fix this and / or work around the issue? Thanks!

mitchdowney commented 6 years ago

Whoops 100% my bad. I had on error handling setup for the request, but not the feedParser instance itself 😳

Problem is solved. FeedParser is great, thanks for building it!

danmactough commented 6 years ago

Thanks @mitchdowney. Glad you figured it out!