diff options
author | Masaya Suzuki <masayasuzuki@google.com> | 2016-08-23 17:57:59 -0700 |
---|---|---|
committer | Masaya Suzuki <masayasuzuki@google.com> | 2016-08-23 18:06:51 -0700 |
commit | c4e209b20fe519f419be0300ed414350649df88f (patch) | |
tree | 2b9505f07f466d698b3615117a8061597642c8f2 /org.eclipse.jgit/src/org/eclipse/jgit/transport | |
parent | 1096652e71257720fcf5bc90ccfa367293bd8ce2 (diff) | |
download | jgit-c4e209b20fe519f419be0300ed414350649df88f.tar.gz jgit-c4e209b20fe519f419be0300ed414350649df88f.zip |
Add HTTP status code to ServiceMayNotContinueException
The exception can be thrown in a various reason, and sometimes 403
Forbidden is not appropriate. Make the HTTP status code customizable.
Change-Id: If2ef6f454f7479158a4e28a12909837db483521c
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/transport')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/ServiceMayNotContinueException.java | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ServiceMayNotContinueException.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ServiceMayNotContinueException.java index e000cfbe64..ce5ccaa65d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ServiceMayNotContinueException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ServiceMayNotContinueException.java @@ -44,6 +44,7 @@ package org.eclipse.jgit.transport; import java.io.IOException; +import javax.servlet.http.HttpServletResponse; import org.eclipse.jgit.internal.JGitText; @@ -55,11 +56,13 @@ import org.eclipse.jgit.internal.JGitText; public class ServiceMayNotContinueException extends IOException { private static final long serialVersionUID = 1L; + private final int statusCode; private boolean output; /** Initialize with no message. */ public ServiceMayNotContinueException() { // Do not set a message. + statusCode = HttpServletResponse.SC_FORBIDDEN; } /** @@ -69,6 +72,20 @@ public class ServiceMayNotContinueException extends IOException { */ public ServiceMayNotContinueException(String msg) { super(msg); + statusCode = HttpServletResponse.SC_FORBIDDEN; + } + + /** + * @param msg + * a message explaining why it cannot continue. This message may + * be shown to an end-user. + * @param statusCode + * the HTTP status code. + * @since 4.5 + */ + public ServiceMayNotContinueException(String msg, int statusCode) { + super(msg); + this.statusCode = statusCode; } /** @@ -80,8 +97,24 @@ public class ServiceMayNotContinueException extends IOException { * @since 3.2 */ public ServiceMayNotContinueException(String msg, Throwable cause) { - super(msg); - initCause(cause); + super(msg, cause); + statusCode = HttpServletResponse.SC_FORBIDDEN; + } + + /** + * @param msg + * a message explaining why it cannot continue. This message may + * be shown to an end-user. + * @param cause + * the cause of the exception. + * @param statusCode + * the HTTP status code. + * @since 4.5 + */ + public ServiceMayNotContinueException( + String msg, Throwable cause, int statusCode) { + super(msg, cause); + this.statusCode = statusCode; } /** @@ -104,4 +137,12 @@ public class ServiceMayNotContinueException extends IOException { public void setOutput() { output = true; } + + /** + * @return true if the message was already output to the client. + * @since 4.5 + */ + public int getStatusCode() { + return statusCode; + } } |