mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
GUACAMOLE-567: Rely on HTTP or WebSocket status code to determine error if Guacamole-specific reason is missing. Default to server unreachable.
This commit is contained in:
@@ -382,10 +382,23 @@ Guacamole.HTTPTunnel = function(tunnelURL, crossDomain, extraTunnelHeaders) {
|
|||||||
|
|
||||||
function handleHTTPTunnelError(xmlhttprequest) {
|
function handleHTTPTunnelError(xmlhttprequest) {
|
||||||
|
|
||||||
|
// Pull status code directly from headers provided by Guacamole
|
||||||
var code = parseInt(xmlhttprequest.getResponseHeader("Guacamole-Status-Code"));
|
var code = parseInt(xmlhttprequest.getResponseHeader("Guacamole-Status-Code"));
|
||||||
|
if (code) {
|
||||||
var message = xmlhttprequest.getResponseHeader("Guacamole-Error-Message");
|
var message = xmlhttprequest.getResponseHeader("Guacamole-Error-Message");
|
||||||
|
|
||||||
close_tunnel(new Guacamole.Status(code, message));
|
close_tunnel(new Guacamole.Status(code, message));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failing that, derive a Guacamole status code from the HTTP status
|
||||||
|
// code provided by the browser
|
||||||
|
else if (xmlhttprequest.status)
|
||||||
|
close_tunnel(new Guacamole.Status(
|
||||||
|
Guacamole.Status.Code.fromHTTPCode(xmlhttprequest.status),
|
||||||
|
xmlhttprequest.statusText));
|
||||||
|
|
||||||
|
// Otherwise, assume server is unreachable
|
||||||
|
else
|
||||||
|
close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_NOT_FOUND));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -808,11 +821,20 @@ Guacamole.WebSocketTunnel = function(tunnelURL) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
socket.onclose = function(event) {
|
socket.onclose = function(event) {
|
||||||
close_tunnel(new Guacamole.Status(parseInt(event.reason), event.reason));
|
|
||||||
};
|
|
||||||
|
|
||||||
socket.onerror = function(event) {
|
// Pull status code directly from closure reason provided by Guacamole
|
||||||
close_tunnel(new Guacamole.Status(Guacamole.Status.Code.SERVER_ERROR, event.data));
|
if (event.reason)
|
||||||
|
close_tunnel(new Guacamole.Status(parseInt(event.reason), event.reason));
|
||||||
|
|
||||||
|
// Failing that, derive a Guacamole status code from the WebSocket
|
||||||
|
// status code provided by the browser
|
||||||
|
else if (event.code)
|
||||||
|
close_tunnel(new Guacamole.Status(Guacamole.Status.Code.fromWebSocketCode(event.code)));
|
||||||
|
|
||||||
|
// Otherwise, assume server is unreachable
|
||||||
|
else
|
||||||
|
close_tunnel(new Guacamole.Status(Guacamole.Status.Code.UPSTREAM_NOT_FOUND));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.onmessage = function(event) {
|
socket.onmessage = function(event) {
|
||||||
@@ -1141,51 +1163,6 @@ Guacamole.StaticHTTPTunnel = function StaticHTTPTunnel(url, crossDomain, extraTu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the Guacamole protocol status code which most closely
|
|
||||||
* represents the given HTTP status code.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Number} httpStatus
|
|
||||||
* The HTTP status code to translate into a Guacamole protocol status
|
|
||||||
* code.
|
|
||||||
*
|
|
||||||
* @returns {Number}
|
|
||||||
* The Guacamole protocol status code which most closely represents the
|
|
||||||
* given HTTP status code.
|
|
||||||
*/
|
|
||||||
var getGuacamoleStatusCode = function getGuacamoleStatusCode(httpStatus) {
|
|
||||||
|
|
||||||
// Translate status codes with known equivalents
|
|
||||||
switch (httpStatus) {
|
|
||||||
|
|
||||||
// HTTP 400 - Bad request
|
|
||||||
case 400:
|
|
||||||
return Guacamole.Status.Code.CLIENT_BAD_REQUEST;
|
|
||||||
|
|
||||||
// HTTP 403 - Forbidden
|
|
||||||
case 403:
|
|
||||||
return Guacamole.Status.Code.CLIENT_FORBIDDEN;
|
|
||||||
|
|
||||||
// HTTP 404 - Resource not found
|
|
||||||
case 404:
|
|
||||||
return Guacamole.Status.Code.RESOURCE_NOT_FOUND;
|
|
||||||
|
|
||||||
// HTTP 429 - Too many requests
|
|
||||||
case 429:
|
|
||||||
return Guacamole.Status.Code.CLIENT_TOO_MANY;
|
|
||||||
|
|
||||||
// HTTP 503 - Server unavailable
|
|
||||||
case 503:
|
|
||||||
return Guacamole.Status.Code.SERVER_BUSY;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default all other codes to generic internal error
|
|
||||||
return Guacamole.Status.Code.SERVER_ERROR;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
this.sendMessage = function sendMessage(elements) {
|
this.sendMessage = function sendMessage(elements) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
};
|
};
|
||||||
@@ -1248,7 +1225,8 @@ Guacamole.StaticHTTPTunnel = function StaticHTTPTunnel(url, crossDomain, extraTu
|
|||||||
|
|
||||||
// Fail if file could not be downloaded via HTTP
|
// Fail if file could not be downloaded via HTTP
|
||||||
if (tunnel.onerror)
|
if (tunnel.onerror)
|
||||||
tunnel.onerror(new Guacamole.Status(getGuacamoleStatusCode(xhr.status), xhr.statusText));
|
tunnel.onerror(new Guacamole.Status(
|
||||||
|
Guacamole.Status.Code.fromHTTPCode(xhr.status), xhr.statusText));
|
||||||
|
|
||||||
tunnel.disconnect();
|
tunnel.disconnect();
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user