How to catch errors?

#1

Hi, this is a really basic question, but how do I go about catching Autobahn JS errors?

As an example, I’m getting the following output in my console:

autobahn.1429491778.min.js:formatted:2457 WebSocket connection to ‘ws://dev.pricewombat.com:9090/’ failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I tried putting my connection code inside of a try/catch block, but the above error is still logged in the console and my code in the catch block is never executed.

try {

if (typeof autobahn !== “undefined”) {

var connection = new autobahn.Connection({

url: priceWombat.localhost ? ‘ws://dev.pricewombat.com:9090’ : ‘wss://www.pricewombat.com:9090’,

realm: ‘restricted_realm’

});

connection.onopen = function (session) {

priceWombat.webSocketOpened = true;

priceWombat.webSocket = session;

$(window).on(‘beforeunload’, function () {

connection.close();

});

window.onbeforeunload = function () {

connection.close();

};

};

connection.open();

}

} catch (e) {

console.log('error caught: ’ + e);

}

0 Likes

#2

Errors from establishing a connection (or loosing one) can be processed using the `onclose` callback:

http://autobahn.ws/js/programming.html#establishing-a-wamp-connection

···

Am 16.09.2015 um 15:26 schrieb Nate:

Hi, this is a really basic question, but how do I go about catching
Autobahn JS errors?

0 Likes

#3

Hi!

In addition to Tobias’ answer:

The ‘connection.open()’ call itself doesn’t fail. It triggers the connection process within the library, and this may fail much, much later, e.g. if you have a high number of retries configured.

Regards,

Alex

···

Am Mittwoch, 16. September 2015 15:26:51 UTC+2 schrieb Nate:

Hi, this is a really basic question, but how do I go about catching Autobahn JS errors?

As an example, I’m getting the following output in my console:

autobahn.1429491778.min.js:formatted:2457 WebSocket connection to ‘ws://dev.pricewombat.com:9090/’ failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I tried putting my connection code inside of a try/catch block, but the above error is still logged in the console and my code in the catch block is never executed.

try {

if (typeof autobahn !== “undefined”) {

var connection = new autobahn.Connection({

url: priceWombat.localhost ? ‘ws://dev.pricewombat.com:9090’ : ‘wss://www.pricewombat.com:9090’,

realm: ‘restricted_realm’

});

connection.onopen = function (session) {

priceWombat.webSocketOpened = true;

priceWombat.webSocket = session;

$(window).on(‘beforeunload’, function () {

connection.close();

});

window.onbeforeunload = function () {

connection.close();

};

};

connection.open();

}

} catch (e) {

console.log('error caught: ’ + e);

}

0 Likes

#4

How to catch session.register errors?

The documentation says (here), “A registration may also fail, e.g. when a procedure is already registered under the given URI or when the session is not authorized to register procedures.”

But it does not indicate how to know when such errors happen (with Autobahn.js) or how to deal with such situations correctly.

GK

···

On Wednesday, September 16, 2015 at 6:56:51 PM UTC+5:30, Nate wrote:

Hi, this is a really basic question, but how do I go about catching Autobahn JS errors?

As an example, I’m getting the following output in my console:

autobahn.1429491778.min.js:formatted:2457 WebSocket connection to ‘ws://dev.pricewombat.com:9090/’ failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I tried putting my connection code inside of a try/catch block, but the above error is still logged in the console and my code in the catch block is never executed.

try {

if (typeof autobahn !== “undefined”) {

var connection = new autobahn.Connection({

url: priceWombat.localhost ? ‘ws://dev.pricewombat.com:9090’ : ‘wss://www.pricewombat.com:9090’,

realm: ‘restricted_realm’

});

connection.onopen = function (session) {

priceWombat.webSocketOpened = true;

priceWombat.webSocket = session;

$(window).on(‘beforeunload’, function () {

connection.close();

});

window.onbeforeunload = function () {

connection.close();

};

};

connection.open();

}

} catch (e) {

console.log('error caught: ’ + e);

}

0 Likes

#5

Hi!

Take a look at http://autobahn.ws/js/reference.html#register

The registration call returns a promise, which is either resolved or rejected depending on whether the registration is successful or fails. On success, the first callback you attach is called with the registration data, or the second one with the error.

Regards,

Alex

···

Am Dienstag, 12. Januar 2016 08:26:07 UTC+1 schrieb Gopalakrishna Palem:

How to catch session.register errors?

The documentation says (here), “A registration may also fail, e.g. when a procedure is already registered under the given URI or when the session is not authorized to register procedures.”

But it does not indicate how to know when such errors happen (with Autobahn.js) or how to deal with such situations correctly.

GK

On Wednesday, September 16, 2015 at 6:56:51 PM UTC+5:30, Nate wrote:

Hi, this is a really basic question, but how do I go about catching Autobahn JS errors?

As an example, I’m getting the following output in my console:

autobahn.1429491778.min.js:formatted:2457 WebSocket connection to ‘ws://dev.pricewombat.com:9090/’ failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I tried putting my connection code inside of a try/catch block, but the above error is still logged in the console and my code in the catch block is never executed.

try {

if (typeof autobahn !== “undefined”) {

var connection = new autobahn.Connection({

url: priceWombat.localhost ? ‘ws://dev.pricewombat.com:9090’ : ‘wss://www.pricewombat.com:9090’,

realm: ‘restricted_realm’

});

connection.onopen = function (session) {

priceWombat.webSocketOpened = true;

priceWombat.webSocket = session;

$(window).on(‘beforeunload’, function () {

connection.close();

});

window.onbeforeunload = function () {

connection.close();

};

};

connection.open();

}

} catch (e) {

console.log('error caught: ’ + e);

}

0 Likes