diff --git a/core/src/main/java/io/confluent/rest/exceptions/RestServerErrorException.java b/core/src/main/java/io/confluent/rest/exceptions/RestServerErrorException.java new file mode 100644 index 0000000000..efdf105728 --- /dev/null +++ b/core/src/main/java/io/confluent/rest/exceptions/RestServerErrorException.java @@ -0,0 +1,14 @@ +package io.confluent.rest.exceptions; + +import javax.ws.rs.core.Response; + +public class RestServerErrorException extends RestException { + + public RestServerErrorException(String message, int errorCode) { + this(message, errorCode, null); + } + + public RestServerErrorException(String message, int errorCode, Throwable cause) { + super(message, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), errorCode, cause); + } +} diff --git a/core/src/test/java/io/confluent/rest/ExceptionHandlingTest.java b/core/src/test/java/io/confluent/rest/ExceptionHandlingTest.java index 17bb4cf22f..2352be9dba 100644 --- a/core/src/test/java/io/confluent/rest/ExceptionHandlingTest.java +++ b/core/src/test/java/io/confluent/rest/ExceptionHandlingTest.java @@ -31,6 +31,7 @@ import io.confluent.rest.entities.ErrorMessage; import io.confluent.rest.exceptions.RestNotFoundException; +import io.confluent.rest.exceptions.RestServerErrorException; import static org.junit.Assert.assertEquals; @@ -86,7 +87,7 @@ public void testNonRestException() { public void testUnexpectedException() { // Under non-debug mode, this uses a completely generic message since unexpected errors // is the one case we want to be certain we don't leak extra info - testAppException("/unexpected", 500, 500, + testAppException("/unexpected", 500, 50001, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase()); } @@ -122,7 +123,7 @@ public String notFound() { @GET @Path("/unexpected") public String unexpected() { - throw new RuntimeException("Internal server error."); + throw new RestServerErrorException("Internal Server Error", 50001); } }