Example episode payload
{ description : "Isaac Z. Schlueter, James Halliday, Felix Geisendörfer, and Maciej Małecki on New ECMAScript Features, What's Next Up for Node, Stability, Domains, HTTP Parsers, Difflet, Tests, Give, Listener Questions and More!",
duration : 5338,
enclosure : {
filesize : 0,
type : "audio/mpeg",
url : "http://feedproxy.google.com/~r/NodeUp/~5/J8aawbHCeDk/NodeUpThirteen.mp3",
__proto__ : 'Object'
},
guid : "http://www.podtrac.com/pts/redirect.mp3/www.archive.org/download/NodeupThirteen_710/NodeUpThirteen.mp3",
published : "2012-02-20T00:00:00.000Z",
title : "Thirteen: A beautiful tomato show",
}
In 'Planet Money' I was running into a bug where one of its episodes did not have an enclosure property. Node would throw an error and crash every time it ran through the parser.
const feedGenerator = (channelId, cb) => {
itunesLookup(channelId, (err, podcasts) => {
if (err) {
console.log(err);
return cb(err, null);
}
const podcast = JSON.parse(podcasts).results[0];
requestRss(podcast.feedUrl, (err, feed) => {
if (err) {
console.log(err);
return cb(err, null);
}
// line below is mapping the .enclosure.url key, but what if an episode does not have an enclosure prop?
// js engine will throw an error if we try to access a prop on an undefined value. Removing the line ensures we don't have this error.
feed.episodes.map(episode => episode.url = episode.enclosure.url);
cb(err, feed.episodes);
});
});
In 'FeedItemView.jsx', the below ternary operator checks if episode.enclosure is a readable value. If yes, display it - else display nothing.
{this.props.episode.enclosure ? <span style={styles.durationStyle}>{this.props.episode.enclosure.url}</span> : null}
Ugh this was totally my fault. Such a slick fix Chase!