Permalink
Browse files

Fix issue #22 - Don't emit an `error` event when using CPS unless the…

…re is also a handler attached to the `error` event.
  • Loading branch information...
danmactough committed Aug 16, 2012
1 parent ae90d7c commit 70ccf31d9cf1a2736037c3c0d2f9b17f9b24a5c1
Showing with 22 additions and 1 deletion.
  1. +5 −1 main.js
  2. +17 −0 test/parseUrl404.js
View
@@ -766,7 +766,11 @@ FeedParser.prototype.handleSaxError = function (e, scope){
FeedParser.prototype.handleError = function (e, scope, next){
var parser = scope;
- parser.emit('error', e);
+ // Only emit the error event if we are not using CPS or
+ // if we have a listener on 'error' even if we are using CPS
+ if (!parser.callback || parser.listeners('error').length) {
+ parser.emit('error', e);
+ }
parser.errors.push(e);
if (typeof next === 'function') {
next();
View
@@ -0,0 +1,17 @@
+var assert = require('assert')
+ , FeedParser = require('../')
+ , feedparser = new FeedParser()
+ ;
+
+describe('feedparser', function(){
+ describe('#parseUrl', function(){
+ it('should return http error: getaddrinfo ENOENT', function(done) {
+ this.timeout(10000);
+ feedparser.parseUrl('http://nonexistingdomaincausinganerror.com/feed.rss', function (error, meta, articles) {
+ assert.ifError(!error);
+ assert.equal(error.message, 'getaddrinfo ENOENT');
+ done();
+ });
+ });
+ });
+});

0 comments on commit 70ccf31

Please sign in to comment.