mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-31 02:21:36 +00:00
minor style
This commit is contained in:
parent
0f57bfcd28
commit
2cb749d739
@ -54,7 +54,8 @@ HTTPTracker.prototype.announce = function (opts) {
|
||||
})
|
||||
if (self._trackerId) params.trackerid = self._trackerId
|
||||
|
||||
self._request(self.announceUrl, params, function (data) {
|
||||
self._request(self.announceUrl, params, function (err, data) {
|
||||
if (err) return self.client.emit('warning', err)
|
||||
self._onAnnounceResponse(data)
|
||||
})
|
||||
}
|
||||
@ -76,7 +77,8 @@ HTTPTracker.prototype.scrape = function (opts) {
|
||||
var params = {
|
||||
info_hash: infoHashes
|
||||
}
|
||||
self._request(self.scrapeUrl, params, function (data) {
|
||||
self._request(self.scrapeUrl, params, function (err, data) {
|
||||
if (err) return self.client.emit('warning', err)
|
||||
self._onScrapeResponse(data)
|
||||
})
|
||||
}
|
||||
@ -142,25 +144,25 @@ HTTPTracker.prototype._request = function (requestUrl, params, cb) {
|
||||
cleanup()
|
||||
if (self.destroyed) return
|
||||
|
||||
if (err) return self.client.emit('warning', err)
|
||||
if (err) return cb(err)
|
||||
if (res.statusCode !== 200) {
|
||||
return self.client.emit('warning', new Error('Non-200 response code ' +
|
||||
return cb(new Error('Non-200 response code ' +
|
||||
res.statusCode + ' from ' + self.announceUrl))
|
||||
}
|
||||
if (!data || data.length === 0) {
|
||||
return self.client.emit('warning', new Error('Invalid tracker response from' +
|
||||
return cb(new Error('Invalid tracker response from' +
|
||||
self.announceUrl))
|
||||
}
|
||||
|
||||
try {
|
||||
data = bencode.decode(data)
|
||||
} catch (err) {
|
||||
return self.client.emit('warning', new Error('Error decoding tracker response: ' + err.message))
|
||||
return cb(new Error('Error decoding tracker response: ' + err.message))
|
||||
}
|
||||
var failure = data['failure reason']
|
||||
if (failure) {
|
||||
debug('failure from ' + requestUrl + ' (' + failure + ')')
|
||||
return self.client.emit('warning', new Error(failure))
|
||||
return cb(new Error(failure))
|
||||
}
|
||||
|
||||
var warning = data['warning message']
|
||||
@ -171,7 +173,7 @@ HTTPTracker.prototype._request = function (requestUrl, params, cb) {
|
||||
|
||||
debug('response from ' + requestUrl)
|
||||
|
||||
cb(data)
|
||||
cb(null, data)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user