Skip to content

Commit

Permalink
putting try/catch around whole XML parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mncaudill committed Oct 20, 2011
1 parent 6a4aa2e commit 3bef5e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
46 changes: 23 additions & 23 deletions flickr-conduit.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,30 @@ var parseFlickrPost = function(content, callback) {
var xml = new xml2js.Parser();
var imgObjs = [];
xml.on('end', function(data) {
// We possibly get multiple entries per POST
var entries = Array.isArray(data.entry) ? data.entry : [data.entry];

var imgData = null;
var photoUrl= null;
for (var i in entries) {
try {
imgData = entries[i]['media:content']['@'];

// Dumb, but there's a bug in the xml2js that messes up on the <link> tab. (Or I'm missing something.)
var id = entries[i]['id'].split(':')[2].split('/')[2];
photoUrl = entries[i].author.uri.replace("http://www.flickr.com/people/", 'http://www.flickr.com/photos/');
photoUrl += id + '/';

imgObjs.push({
url: imgData.url,
width: imgData.width,
height: imgData.height,
link: photoUrl,
raw: entries[i],
});
} catch (e) {
// Noop
try {
// We possibly get multiple entries per POST
var entries = Array.isArray(data.entry) ? data.entry : [data.entry];

var imgData = null;
var photoUrl= null;
for (var i in entries) {
imgData = entries[i]['media:content']['@'];

// Dumb, but there's a bug in the xml2js that messes up on the <link> tab. (Or I'm missing something.)
var id = entries[i]['id'].split(':')[2].split('/')[2];
photoUrl = entries[i].author.uri.replace("http://www.flickr.com/people/", 'http://www.flickr.com/photos/');
photoUrl += id + '/';

imgObjs.push({
url: imgData.url,
width: imgData.width,
height: imgData.height,
link: photoUrl,
raw: entries[i],
});
}
} catch (e) {
// Noop
}
callback(imgObjs);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Nolan Caudill <nolan@nolancaudill.com> (http://nolancaudill.com)",
"name": "flickr-conduit",
"description": "A subscriber endpoint for Flickr's real-time PuSH feed",
"version": "0.1.3",
"version": "0.1.4",
"homepage": "https://github.com/mncaudill/flickr-conduit",
"repository": {
"type": "git",
Expand Down

0 comments on commit 3bef5e9

Please sign in to comment.