示例代码:
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);
});
它不会在我的 Chrome 控制台中抛出错误。
你有解决这个问题的想法吗?
最佳答案
是的,Strophe 经常自己捕获错误,目前不提供任何获取连接错误信息的能力。虽然错误捕获是可以的,但不能自己捕获错误不是很好。但是您可以使用以下代码修复它:
$().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);
});
其中 myErrorHandler
是您的自定义连接错误处理程序。
关于javascript - 为什么 Strophe.js 没有抛出错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8285053/