You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to catch errors from blather. I'm totally new to event machine and thread programming in ruby, so maybe this looks silly, but ...
I've created a blather client successfully like this:
# client.rbrequire'eventmachine'require'blather/client/dsl'classClientincludeBlather::DSLdefinitializesetup'jabber@id/name','password'enddefconnectThread.newdoEM.run{client.connect}endenddefconnected?client.connected?endendclient=Client.newclient.connectuntilclient.connected?puts'Waiting for connection ...'sleep1endclient.say'some@jid','hello!'sleep1000
This works good so far.
I can now trigger the error Stream Error (conflict): Replaced by new connection by simply running this script twice:
ruby client.rb & ruby client.rb
This error is OK of course, but how can I catch it so I can handle it in a custom way? I tried to rescue it everywhere without success, so it looks like this now:
I'm not sure if this is exactly the same, because overwriting unbind as in #73 didn't work for me, but I managed to register a custom error handler which at least gets called additionally like this:
classBlather::Clientattr_accessor:custom_error_handleralias_method:setup_initial_handlers_orig,:setup_initial_handlersdefsetup_initial_handlersregister_handler:errordo |err|
custom_error_handler.call(err)ifcustom_error_handlerendsetup_initial_handlers_origendendclassClientincludeBlather::DSLdefinitializeclient.custom_error_handler=procdo |err|
# will get called on error like StreamErrorendendend
I'm trying to catch errors from blather. I'm totally new to event machine and thread programming in ruby, so maybe this looks silly, but ...
I've created a blather client successfully like this:
This works good so far.
I can now trigger the error
Stream Error (conflict): Replaced by new connection
by simply running this script twice:This error is OK of course, but how can I catch it so I can handle it in a custom way? I tried to rescue it everywhere without success, so it looks like this now:
But the error is never catched, even with this connect monstrosity above. What am I missing?
The text was updated successfully, but these errors were encountered: