Permalink
Browse files

Add url to error when possible. Change "Not a feed" error message bec…

…ause it's not always a remote server. Update tests. Closes #43."
  • Loading branch information...
1 parent 73a9c4e commit 761456b0b4eaafef3f1ca3cc15649113cdc052dd @danmactough committed Feb 18, 2013
Showing with 27 additions and 3 deletions.
  1. +6 −1 main.js
  2. +3 −2 test/notaFeed.js
  3. +18 −0 test/parseUrl404.js
View
@@ -263,7 +263,11 @@ FeedParser.prototype.handleEnd = function (){
// parsing a feed
if (!this.errors.length && this.meta && !this.meta['#type']) {
this.meta['#type'] = 'INVALID'; // Set a value so we don't cause an infinite loop
- return this.handleError(new Error('Remote server did not respond with a feed'));
+ var e = new Error('Not a feed');
+ if (this.response && this.response.request && this.response.request.href) {
+ e.url = this.response.request.href;
+ }
+ return this.handleError(e);
}
if ('function' === typeof this.callback) {
if (this.errors.length) {
@@ -1254,6 +1258,7 @@ FeedParser.parseUrl = function (url, options, callback) {
else {
e.message = 'Remote server responded: ' + codeReason;
e.code = code;
+ e.url = url;
fp.handleError(e);
response.request && response.request.abort();
}
View
@@ -16,7 +16,7 @@ describe('feedparser', function(){
it('should call back with an error and no meta or articles', function(done) {
feedparser.parseUrl(feed, function (error, meta, articles) {
assert.ok(error instanceof Error);
- assert.equal(error.message, 'Remote server did not respond with a feed');
+ assert.equal(error.message, 'Not a feed');
assert.equal(meta, null);
assert.equal(articles, null);
done();
@@ -27,7 +27,8 @@ describe('feedparser', function(){
it('should call back with an error and no meta or articles', function(done) {
FeedParser.parseUrl(feed, function (error, meta, articles) {
assert.ok(error instanceof Error);
- assert.equal(error.message, 'Remote server did not respond with a feed');
+ assert.equal(error.message, 'Not a feed');
+ assert.equal(error.url, feed);
assert.equal(meta, null);
assert.equal(articles, null);
done();
View
@@ -26,4 +26,22 @@ describe('feedparser', function(){
});
});
});
+ describe('.parseUrl', function () {
+
+ before(function (done) {
+ server(done);
+ });
+
+ after(function (done) {
+ server.close(done);
+ });
+
+ it('should return a 404 error', function (done) {
+ FeedParser.parseUrl('http://localhost:21337/nosuchfeed.xml', function (error, meta, articles) {
+ assert(error instanceof Error, error.message);
+ assert.equal(error.code, 404);
+ done();
+ });
+ });
+ })
});

0 comments on commit 761456b

Please sign in to comment.