Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how I cand handle errors when adding torrents to a client? #1210

Closed
rafaelleru opened this issue Oct 22, 2017 · 4 comments
Closed

how I cand handle errors when adding torrents to a client? #1210

rafaelleru opened this issue Oct 22, 2017 · 4 comments

Comments

@rafaelleru
Copy link

@rafaelleru rafaelleru commented Oct 22, 2017

I tryed client.add(t, function(err, torrent){manage error if it happens here}) but didn't work.

@alxhotel

This comment has been minimized.

Copy link
Member

@alxhotel alxhotel commented Oct 22, 2017

I believe you can do something like this:

client.on('error', function (err) {
  // Handle error
})
client.on('warning', function (err) {
  // Handle warning
})
@rafaelleru

This comment has been minimized.

Copy link
Author

@rafaelleru rafaelleru commented Oct 22, 2017

Yes but I want to manage the duplicated torrent and invalid torrent identifier when adding a torrent.
So I need to get the errors in the callback client.add(torrent, callback(err, torrent))

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Oct 22, 2017

@rafaelleru You need to use the error event of the client.

The onTorrent callback function of client.add is not an error-first callback function.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Apr 18, 2018

You can also listen for the 'error' event on the torrent object, which is more specific than the client 'error' event.

torrent.on('error', function (err) {})

From the docs:

Note: Torrent errors are emitted at torrent.on('error'). If there are no 'error' event handlers on the torrent instance, then the error will be emitted at client.on('error'). This prevents throwing an uncaught exception (unhandled 'error' event), but it makes it impossible to distinguish client errors versus torrent errors. Torrent errors are not fatal, and the client is still usable afterwards. Therefore, always listen for errors in both places (client.on('error') and torrent.on('error')).

@lock lock bot locked as resolved and limited conversation to collaborators Jul 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.