diff --git a/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleClientException.java b/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleClientException.java index 543392032..667f416ec 100644 --- a/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleClientException.java +++ b/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleClientException.java @@ -22,6 +22,8 @@ package org.glyptodon.guacamole; +import org.glyptodon.guacamole.protocol.GuacamoleStatus; + /** * A generic exception thrown when part of the Guacamole API encounters @@ -62,4 +64,9 @@ public class GuacamoleClientException extends GuacamoleException { super(cause); } + @Override + public GuacamoleStatus getStatus() { + return GuacamoleStatus.CLIENT_BAD_REQUEST; + } + } diff --git a/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleException.java b/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleException.java index b7a67727e..412c0e961 100644 --- a/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleException.java +++ b/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleException.java @@ -22,6 +22,8 @@ package org.glyptodon.guacamole; +import org.glyptodon.guacamole.protocol.GuacamoleStatus; + /** * A generic exception thrown when parts of the Guacamole API encounter @@ -30,7 +32,7 @@ package org.glyptodon.guacamole; * @author Michael Jumper */ public class GuacamoleException extends Exception { - + /** * Creates a new GuacamoleException with the given message and cause. * @@ -61,4 +63,15 @@ public class GuacamoleException extends Exception { super(cause); } + /** + * Returns the Guacamole status associated with this exception. This status + * can then be easily translated into an HTTP error code or Guacamole + * protocol error code. + * + * @return The corresponding Guacamole status. + */ + public GuacamoleStatus getStatus() { + return GuacamoleStatus.SERVER_ERROR; + } + } diff --git a/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleResourceNotFoundException.java b/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleResourceNotFoundException.java index 93810854c..3794c2431 100644 --- a/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleResourceNotFoundException.java +++ b/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleResourceNotFoundException.java @@ -22,6 +22,8 @@ package org.glyptodon.guacamole; +import org.glyptodon.guacamole.protocol.GuacamoleStatus; + /** * A generic exception thrown when part of the Guacamole API fails to find @@ -62,4 +64,9 @@ public class GuacamoleResourceNotFoundException extends GuacamoleClientException super(cause); } + @Override + public GuacamoleStatus getStatus() { + return GuacamoleStatus.RESOURCE_NOT_FOUND; + } + } diff --git a/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleSecurityException.java b/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleSecurityException.java index 9e95ee760..417e5d206 100644 --- a/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleSecurityException.java +++ b/guacamole-common/src/main/java/org/glyptodon/guacamole/GuacamoleSecurityException.java @@ -22,6 +22,8 @@ package org.glyptodon.guacamole; +import org.glyptodon.guacamole.protocol.GuacamoleStatus; + /** * A security-related exception thrown when parts of the Guacamole API is @@ -61,4 +63,9 @@ public class GuacamoleSecurityException extends GuacamoleClientException { super(cause); } + @Override + public GuacamoleStatus getStatus() { + return GuacamoleStatus.CLIENT_FORBIDDEN; + } + }