function getFeed (feedUrl, callback) {
// Get a response stream
fetch(feedUrl, {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36',
'accept': 'text/html,application/xhtml+xml'
}).then(function (res) {
console.error('node-fetch status: %s', res.status);
// Setup feedparser stream
var feedparser = new FeedParser();
var feedItems = [];
feedparser.on('error', function() {
console.error('## RRfeedUrl: %s (%s)', feedUrl, res.status);
return callback('Unknown error');
});
feedparser.on('end', done);
feedparser.on('readable', function() {
try {
var item = this.read();
if (item !== null) feedItems.push (item);
}
catch (err) {
console.error('## ERR (%s)', err.message);
}
}).on ('end', function () {
var meta = this.meta;
return callback (null, feedItems, meta.title, meta.link);
});
if (res.status != 200) {
return callback(res.status);
}
var charset = getParams(res.headers.get('content-type') || '').charset;
var responseStream = res.body;
responseStream = maybeTranslate(responseStream, charset);
responseStream.pipe(feedparser);
}).catch((err) => {
console.error('## ERR (%s)', err.message);
return callback(err);
});
}
Finer inspection reveals a pending promise ; How can I resolve it and move on?
I tried using redirect: 'manual' in the fetch call, but it makes a lot of otherwise fine feed URLs fail ; I'm really not sure if I have to track and handle those redirect problems at the fetch level, or at the feedParser one, since it follows redirects... Is there a way to detect that the redirect fails?
Sorry, but this is not an issue with Feedparser. At first glance, it just looks like the remote server is incorrectly configured. You'll have to decide how you want to manage that.
Hi, I'm having a problem with a feed URL that is not redirecting properly
URL of the feed: https://www.h24info.ma/feed FeedParser version: 2.2.10 Node version: 14.15.3 NPM version: 7.6.0
There is clearly a problem with the URL itself, as it makes
wget
loop forever:Here is the (entire) curl response:
My code:
Finer inspection reveals a pending promise ; How can I resolve it and move on?
I tried using
redirect: 'manual'
in the fetch call, but it makes a lot of otherwise fine feed URLs fail ; I'm really not sure if I have to track and handle those redirect problems at thefetch
level, or at thefeedParser
one, since it follows redirects... Is there a way to detect that the redirect fails?