File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -45,10 +45,14 @@ var port = 6881
4545
4646var client = new Client (peerId, port, parsedTorrent)
4747
48- // you must add an 'error' event handler!
4948client .on (' error' , function (err ) {
49+ // fatal client error!
5050 console .log (err .message )
51+ })
52+
53+ client .on (' warning' , function (err ) {
5154 // a tracker was unavailable or sent bad data to the client. you can probably ignore it
55+ console .log (err .message )
5256})
5357
5458// start getting peers from the tracker
Original file line number Diff line number Diff line change @@ -388,7 +388,8 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) {
388388 }
389389
390390 function error ( message ) {
391- self . client . emit ( 'error' , new Error ( message + ' (connecting to tracker ' + requestUrl + ')' ) )
391+ // errors will often happen if a tracker is offline, so don't treat it as fatal
392+ self . client . emit ( 'warning' , new Error ( message + ' (' + requestUrl + ')' ) )
392393 cleanup ( )
393394 }
394395
@@ -443,7 +444,7 @@ Tracker.prototype._handleResponse = function (requestUrl, data) {
443444 try {
444445 data = bencode . decode ( data )
445446 } catch ( err ) {
446- return self . client . emit ( 'error ' , new Error ( 'Error decoding tracker response: ' + err . message ) )
447+ return self . client . emit ( 'warning ' , new Error ( 'Error decoding tracker response: ' + err . message ) )
447448 }
448449 var failure = data [ 'failure reason' ]
449450 if ( failure ) {
You can’t perform that action at this time.
0 commit comments