Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why there is no error thrown with Strophe.js?

Example code:

var connection = null;

function onConnect(status) {
    im_a_big_error.log('wtf');
    // Why it doesn't throw me an error here ??                                                                                                                                                                                                
}

$().ready(function() {
    connection = new Strophe.Connection('http://localhost:8080/http-bind');
    connection.connect('admin@localhost', 'admin', onConnect);
});

It doesn't throw me an error in my Chrome console.

Do you have an idea to resolve this issue?

like image 687
Unitech Avatar asked Nov 27 '11 10:11

Unitech


1 Answers

Yes, Strophe often catch errors by itself and currently doesn't provide any ability to get connection error information. While error catching is ok, the impossibility of catching errors by yourself is not very good. But you can fix it with the following code:

$().ready(function() {
    connection = new Strophe.Connection('http://localhost:8080/http-bind');
    connection._hitError = function (reqStatus) {
        this.errors++;
        Strophe.warn("request errored, status: " + reqStatus + ", 
                number of errors: " + this.errors);
        if (this.errors > 4) this._onDisconnectTimeout();
        myErrorHandler(reqStatus, this.errors);
    };
    connection.connect('admin@localhost', 'admin', onConnect);
});

where myErrorHandler is your custom connection error handler.

like image 134
tsds Avatar answered Sep 27 '22 21:09

tsds