Skip to content

Commit

Permalink
Return an error if page format is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish committed Jul 25, 2012
1 parent 7f39a13 commit e178265
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/lanyrd-scraper.js
Expand Up @@ -20,6 +20,11 @@ exports.scrape = function(url, callback) {
return;
}

if ($('h1.summary').length === 0) {
callback(new Error('Invalid page format'), null);
return;
}

helper.setContext($);

var data = {};
Expand Down
7 changes: 7 additions & 0 deletions test/lanyrd-scraper_test.js
Expand Up @@ -46,6 +46,13 @@ exports['multi-day event'] = {
done();
});
},
'returns an error if page content is invalid': function(test) {
test.expect(1);
lanyrd.scrape('http://localhost:' + PORT + '/invalid-page.html', function(err, res){
test.equal(err.message, 'Invalid page format');
test.done();
});
},
'has title': function(test) {
test.expect(1);
test.equal(multiDayEventData.title, 'Web Directions Code');
Expand Down
5 changes: 5 additions & 0 deletions test/mock-pages/invalid-page.html
@@ -0,0 +1,5 @@
<!DOCTYPE html>
<html>
<head></head>
<body></body>
</html>

0 comments on commit e178265

Please sign in to comment.