Skip to content
This repository
Browse code

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...
commit 761456b0b4eaafef3f1ca3cc15649113cdc052dd 1 parent 73a9c4e
Dan MacTough authored February 17, 2013
7  main.js
@@ -263,7 +263,11 @@ FeedParser.prototype.handleEnd = function (){
263 263
   // parsing a feed
264 264
   if (!this.errors.length && this.meta && !this.meta['#type']) {
265 265
     this.meta['#type'] = 'INVALID'; // Set a value so we don't cause an infinite loop
266  
-    return this.handleError(new Error('Remote server did not respond with a feed'));
  266
+    var e = new Error('Not a feed');
  267
+    if (this.response && this.response.request && this.response.request.href) {
  268
+      e.url = this.response.request.href;
  269
+    }
  270
+    return this.handleError(e);
267 271
   }
268 272
   if ('function' === typeof this.callback) {
269 273
     if (this.errors.length) {
@@ -1254,6 +1258,7 @@ FeedParser.parseUrl = function (url, options, callback) {
1254 1258
       else {
1255 1259
         e.message = 'Remote server responded: ' + codeReason;
1256 1260
         e.code = code;
  1261
+        e.url = url;
1257 1262
         fp.handleError(e);
1258 1263
         response.request && response.request.abort();
1259 1264
       }
5  test/notaFeed.js
@@ -16,7 +16,7 @@ describe('feedparser', function(){
16 16
       it('should call back with an error and no meta or articles', function(done) {
17 17
         feedparser.parseUrl(feed, function (error, meta, articles) {
18 18
           assert.ok(error instanceof Error);
19  
-          assert.equal(error.message, 'Remote server did not respond with a feed');
  19
+          assert.equal(error.message, 'Not a feed');
20 20
           assert.equal(meta, null);
21 21
           assert.equal(articles, null);
22 22
           done();
@@ -27,7 +27,8 @@ describe('feedparser', function(){
27 27
       it('should call back with an error and no meta or articles', function(done) {
28 28
         FeedParser.parseUrl(feed, function (error, meta, articles) {
29 29
           assert.ok(error instanceof Error);
30  
-          assert.equal(error.message, 'Remote server did not respond with a feed');
  30
+          assert.equal(error.message, 'Not a feed');
  31
+          assert.equal(error.url, feed);
31 32
           assert.equal(meta, null);
32 33
           assert.equal(articles, null);
33 34
           done();
18  test/parseUrl404.js
@@ -26,4 +26,22 @@ describe('feedparser', function(){
26 26
       });
27 27
     });
28 28
   });
  29
+  describe('.parseUrl', function () {
  30
+
  31
+    before(function (done) {
  32
+      server(done);
  33
+    });
  34
+
  35
+    after(function (done) {
  36
+      server.close(done);
  37
+    });
  38
+
  39
+    it('should return a 404 error', function (done) {
  40
+      FeedParser.parseUrl('http://localhost:21337/nosuchfeed.xml', function (error, meta, articles) {
  41
+        assert(error instanceof Error, error.message);
  42
+        assert.equal(error.code, 404);
  43
+        done();
  44
+      });
  45
+    });
  46
+  })
29 47
 });

0 notes on commit 761456b

Please sign in to comment.
Something went wrong with that request. Please try again.