GUAC-549: Throw status instead of error for connect() in tunnel and client. Pass status instead of message/code parameters for onerror event handlers.

This commit is contained in:
Michael Jumper
2014-03-19 13:58:52 -07:00
parent 52395f6c2e
commit d4a6fd21f7
2 changed files with 31 additions and 47 deletions

View File

@@ -142,9 +142,9 @@ Guacamole.Client = function(tunnel) {
// Array of allocated output streams by index
var output_streams = [];
tunnel.onerror = function(message) {
tunnel.onerror = function(status) {
if (guac_client.onerror)
guac_client.onerror(message);
guac_client.onerror(status);
};
function setState(state) {
@@ -394,8 +394,8 @@ Guacamole.Client = function(tunnel) {
* is being closed.
*
* @event
* @param {String} reason A human-readable reason describing the error.
* @param {Number} code The error code associated with the error.
* @param {Guacamole.Status} status A status object which describes the
* error.
*/
this.onerror = null;
@@ -800,7 +800,7 @@ Guacamole.Client = function(tunnel) {
// Call handler if defined
if (guac_client.onerror)
guac_client.onerror(reason, code);
guac_client.onerror(new Guacamole.Status(code, reason));
guac_client.disconnect();
@@ -1259,6 +1259,7 @@ Guacamole.Client = function(tunnel) {
*
* @param data Arbitrary connection data to be sent to the underlying
* tunnel during the connection process.
* @throws {Guacamole.Status} If an error occurs during connection.
*/
this.connect = function(data) {
@@ -1267,9 +1268,9 @@ Guacamole.Client = function(tunnel) {
try {
tunnel.connect(data);
}
catch (e) {
catch (status) {
setState(STATE_IDLE);
throw e;
throw status;
}
// Ping every 5 seconds (ensure connection alive)