Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2014-05-18 14:45:45 +0400
committerFeross Aboukhadijeh <feross@feross.org>2014-05-18 14:45:45 +0400
commit1c614d171f63009f5f516dab5b9de60cfc28bc05 (patch)
treebdf30ff2de85736b466ea051d9387fab7f769832 /index.js
parent2c41b00c47c16a0a09c5398de5b84f4e35eafa08 (diff)
emit 'error' events for torrent parse errors
Diffstat (limited to 'index.js')
-rw-r--r--index.js15
1 files changed, 11 insertions, 4 deletions
diff --git a/index.js b/index.js
index b80b301..d1903f2 100644
--- a/index.js
+++ b/index.js
@@ -9,6 +9,7 @@ var FSStorage = require('./lib/fs_storage')
var http = require('http')
var inherits = require('inherits')
var mime = require('mime')
+var once = require('once')
var pump = require('pump')
var rangeParser = require('range-parser')
var url = require('url')
@@ -48,6 +49,7 @@ WebTorrent.prototype.add = function (torrentId, opts, cb) {
if (typeof cb !== 'function') {
cb = function () {}
}
+ cb = once(cb)
opts = extend({
storage: FSStorage
@@ -72,16 +74,21 @@ WebTorrent.prototype.add = function (torrentId, opts, cb) {
onTorrentId(torrent)
}))
}).on('error', function (err) {
- cb(new Error('Error downloading torrent from ' + torrentId + '\n' + err.message))
+ err = new Error('Error downloading torrent from ' + torrentId + '\n' + err.message)
+ cb(err)
+ self.emit('error', err)
})
} else {
// assume it's a filesystem path
fs.readFile(torrentId, function (err, torrent) {
if (err) {
- return cb(new Error('Cannot add torrent "' + torrentId + '". Torrent id must be one of: magnet uri, ' +
- 'info hash, torrent file, http url, or filesystem path.'))
+ err = new Error('Cannot add torrent "' + torrentId + '". Torrent id must be one of: magnet uri, ' +
+ 'info hash, torrent file, http url, or filesystem path.')
+ cb(err)
+ self.emit('error', err)
+ } else {
+ onTorrentId(torrent)
}
- onTorrentId(torrent)
})
}