File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -74,11 +74,14 @@ async function main() {
7474 if (res .status !== 200 ) throw new Error (' Bad status code' );
7575
7676 var feedparser = new FeedParser ([options]);
77- feedparser .on (' error' , function (error ) { throw error; });
7877 res .body .pipe (feedparser);
7978
80- for await (var item of feedparser ) {
81- console .log (item .title );
79+ try {
80+ for await (var item of feedparser ) {
81+ console .log (item .title );
82+ }
83+ } catch (err) {
84+ console .error (err);
8285 }
8386}
8487
Original file line number Diff line number Diff line change @@ -14,4 +14,20 @@ describe('examples', function () {
1414
1515 assert . equal ( items . length , 4 ) ;
1616 } ) ;
17+
18+ it ( 'should surface errors via try/catch when using async iterator' , async function ( ) {
19+ var feedparser = new FeedParser ( ) ;
20+ var feed = __dirname + '/feeds/notafeed.html' ;
21+ fs . createReadStream ( feed ) . pipe ( feedparser ) ;
22+
23+ var caught = null ;
24+ try {
25+ for await ( const item of feedparser ) { } // eslint-disable-line no-unused-vars
26+ } catch ( err ) {
27+ caught = err ;
28+ }
29+
30+ assert . ok ( caught instanceof Error ) ;
31+ assert . equal ( caught . message , 'Not a feed' ) ;
32+ } ) ;
1733} ) ;
You can’t perform that action at this time.
0 commit comments