Skip to content

Commit 61cfe0a

Browse files
committed
don't emit 'error' for non-fatal errors
1 parent 1bcb3e4 commit 61cfe0a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ var port = 6881
4545

4646
var client = new Client(peerId, port, parsedTorrent)
4747

48-
// you must add an 'error' event handler!
4948
client.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

client.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)