don't emit 'error' for non-fatal errors

This commit is contained in:
Feross Aboukhadijeh 2014-08-18 01:40:30 -07:00
parent 1bcb3e4097
commit 61cfe0afa6
2 changed files with 8 additions and 3 deletions

View File

@ -45,10 +45,14 @@ var port = 6881
var client = new Client(peerId, port, parsedTorrent)
// you must add an 'error' event handler!
client.on('error', function (err) {
// fatal client error!
console.log(err.message)
})
client.on('warning', function (err) {
// a tracker was unavailable or sent bad data to the client. you can probably ignore it
console.log(err.message)
})
// start getting peers from the tracker

View File

@ -388,7 +388,8 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) {
}
function error (message) {
self.client.emit('error', new Error(message + ' (connecting to tracker ' + requestUrl + ')'))
// errors will often happen if a tracker is offline, so don't treat it as fatal
self.client.emit('warning', new Error(message + ' (' + requestUrl + ')'))
cleanup()
}
@ -443,7 +444,7 @@ Tracker.prototype._handleResponse = function (requestUrl, data) {
try {
data = bencode.decode(data)
} catch (err) {
return self.client.emit('error', new Error('Error decoding tracker response: ' + err.message))
return self.client.emit('warning', new Error('Error decoding tracker response: ' + err.message))
}
var failure = data['failure reason']
if (failure) {