diff --git a/kafka-admin/src/main/java/org/bf2/admin/kafka/admin/handlers/CommonHandler.java b/kafka-admin/src/main/java/org/bf2/admin/kafka/admin/handlers/CommonHandler.java index 931eda58..b1cb1191 100644 --- a/kafka-admin/src/main/java/org/bf2/admin/kafka/admin/handlers/CommonHandler.java +++ b/kafka-admin/src/main/java/org/bf2/admin/kafka/admin/handlers/CommonHandler.java @@ -22,6 +22,7 @@ import org.bf2.admin.kafka.admin.model.Types; import org.jboss.logging.Logger; +import javax.ws.rs.NotFoundException; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.Response.Status.Family; @@ -76,6 +77,7 @@ public ErrorHandler(Class causeType, Function mapper) { // 404 Not Found entry(UnknownTopicOrPartitionException.class, thrown -> errorResponse(thrown, ErrorType.TOPIC_NOT_FOUND)), entry(GroupIdNotFoundException.class, thrown -> errorResponse(thrown, ErrorType.GROUP_NOT_FOUND)), + entry(NotFoundException.class, thrown -> errorResponse(thrown, ErrorType.RESOURCE_NOT_FOUND)), // 409 Conflict entry(TopicExistsException.class, thrown -> errorResponse(thrown, ErrorType.TOPIC_DUPLICATED)), diff --git a/kafka-admin/src/main/java/org/bf2/admin/kafka/admin/model/ErrorType.java b/kafka-admin/src/main/java/org/bf2/admin/kafka/admin/model/ErrorType.java index e703cd28..880f100f 100644 --- a/kafka-admin/src/main/java/org/bf2/admin/kafka/admin/model/ErrorType.java +++ b/kafka-admin/src/main/java/org/bf2/admin/kafka/admin/model/ErrorType.java @@ -35,6 +35,8 @@ public enum ErrorType { UNKNOWN_MEMBER("15", "Unknown consumer group member", Status.BAD_REQUEST), INVALID_REQUEST("16", "Request body or parameters invalid", Status.BAD_REQUEST), // + RESOURCE_NOT_FOUND("17", "No such resource found", Status.NOT_FOUND), + // SERVER_ERROR("99", "Server has encountered an unexpected error", Status.INTERNAL_SERVER_ERROR); public static boolean isCausedBy(Throwable error, Class searchCause) { diff --git a/systemtests/src/test/java/org/bf2/admin/kafka/systemtest/plain/RestEndpointTestIT.java b/systemtests/src/test/java/org/bf2/admin/kafka/systemtest/plain/RestEndpointTestIT.java index b15229f1..facc7351 100644 --- a/systemtests/src/test/java/org/bf2/admin/kafka/systemtest/plain/RestEndpointTestIT.java +++ b/systemtests/src/test/java/org/bf2/admin/kafka/systemtest/plain/RestEndpointTestIT.java @@ -697,4 +697,17 @@ void testOptionsRequestIncludesTwoHourMaxAge() { equalTo(String.valueOf(Duration.ofHours(2).toSeconds()))); } -} \ No newline at end of file + @Test + void testUnknownEndpointReturnsNotFound() { + final ErrorType expectedError = ErrorType.RESOURCE_NOT_FOUND; + given() + .log().ifValidationFails() + .when() + .get("/foo/bar") + .then() + .log().ifValidationFails() + .assertThat() + .statusCode(Status.NOT_FOUND.getStatusCode()) + .body("", matchesError(expectedError)); + } +}