Repository: guacamole-client
Updated Branches:
  refs/heads/master f5266fdde -> c988975ec


GUACAMOLE-567: Add HTTP and WebSocket translation functions to 
Guacamole.Status.Code.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/a1e59b9d
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/a1e59b9d
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/a1e59b9d

Branch: refs/heads/master
Commit: a1e59b9d3aa9b7fda49b9eb5e081700f46580b97
Parents: 1710c31
Author: Michael Jumper <[email protected]>
Authored: Sun Dec 10 17:46:11 2017 -0800
Committer: Michael Jumper <[email protected]>
Committed: Sun May 27 12:28:28 2018 -0700

----------------------------------------------------------------------
 .../src/main/webapp/modules/Status.js           | 84 ++++++++++++++++++++
 1 file changed, 84 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/a1e59b9d/guacamole-common-js/src/main/webapp/modules/Status.js
----------------------------------------------------------------------
diff --git a/guacamole-common-js/src/main/webapp/modules/Status.js 
b/guacamole-common-js/src/main/webapp/modules/Status.js
index ceadaa6..3acfd63 100644
--- a/guacamole-common-js/src/main/webapp/modules/Status.js
+++ b/guacamole-common-js/src/main/webapp/modules/Status.js
@@ -232,3 +232,87 @@ Guacamole.Status.Code = {
     "CLIENT_TOO_MANY": 0x031D
 
 };
+
+/**
+ * Returns the Guacamole protocol status code which most closely
+ * represents the given HTTP status code.
+ *
+ * @param {Number} status
+ *     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.
+ */
+Guacamole.Status.Code.fromHTTPCode = function fromHTTPCode(status) {
+
+    // Translate status codes with known equivalents
+    switch (status) {
+
+        // 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;
+
+};
+
+/**
+ * Returns the Guacamole protocol status code which most closely
+ * represents the given WebSocket status code.
+ *
+ * @param {Number} code
+ *     The WebSocket status code to translate into a Guacamole protocol
+ *     status code.
+ *
+ * @returns {Number}
+ *     The Guacamole protocol status code which most closely represents the
+ *     given WebSocket status code.
+ */
+Guacamole.Status.Code.fromWebSocketCode = function fromWebSocketCode(code) {
+
+    // Translate status codes with known equivalents
+    switch (code) {
+
+        // Successful disconnect (no error)
+        case 1000: // Normal Closure
+            return Guacamole.Status.Code.SUCCESS;
+
+        // Codes which indicate the server is not reachable
+        case 1006: // Abnormal Closure (also signalled by JavaScript when the 
connection cannot be opened in the first place)
+        case 1015: // TLS Handshake
+            return Guacamole.Status.Code.UPSTREAM_NOT_FOUND;
+
+        // Codes which indicate the server is reachable but busy/unavailable
+        case 1001: // Going Away
+        case 1012: // Service Restart
+        case 1013: // Try Again Later
+        case 1014: // Bad Gateway
+            return Guacamole.Status.Code.UPSTREAM_UNAVAILABLE;
+
+    }
+
+    // Default all other codes to generic internal error
+    return Guacamole.Status.Code.SERVER_ERROR;
+
+};

Reply via email to