Skip to content

Commit

Permalink
[Broker] Optimize exception information for schemas (apache#12647)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuruguo authored Nov 6, 2021
1 parent 701df32 commit 36f151c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,11 @@ private static GetSchemaResponse convertSchemaAndMetadataToGetSchemaResponse(Sch
private static void handleGetSchemaResponse(AsyncResponse response, SchemaAndMetadata schema, Throwable error) {
if (isNull(error)) {
if (isNull(schema)) {
response.resume(Response.status(Response.Status.NOT_FOUND).build());
response.resume(Response.status(
Response.Status.NOT_FOUND.getStatusCode(), "Schema not found").build());
} else if (schema.schema.isDeleted()) {
response.resume(Response.status(Response.Status.NOT_FOUND).build());
response.resume(Response.status(
Response.Status.NOT_FOUND.getStatusCode(), "Schema is deleted").build());
} else {
response.resume(Response.ok().encoding(MediaType.APPLICATION_JSON)
.entity(convertSchemaAndMetadataToGetSchemaResponse(schema)).build());
Expand All @@ -290,7 +292,8 @@ private static void handleGetAllSchemasResponse(AsyncResponse response, List<Sch
Throwable error) {
if (isNull(error)) {
if (isNull(schemas)) {
response.resume(Response.status(Response.Status.NOT_FOUND).build());
response.resume(Response.status(
Response.Status.NOT_FOUND.getStatusCode(), "Schemas not found").build());
} else {
response.resume(Response.ok().encoding(MediaType.APPLICATION_JSON)
.entity(GetAllVersionsSchemaResponse.builder()
Expand All @@ -312,7 +315,7 @@ private void validateDestinationAndAdminOperation(boolean authoritative) {
validateTopicOwnership(topicName, authoritative);
} catch (RestException e) {
if (e.getResponse().getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) {
throw new RestException(Response.Status.NOT_FOUND, "Not Found");
throw new RestException(Response.Status.UNAUTHORIZED, e.getMessage());
} else {
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public void testSchemaCLI() throws Exception {
);
fail("Command should have exited with non-zero");
} catch (ContainerExecException e) {
assertTrue(e.getResult().getStderr().contains("Reason: HTTP 404 Not Found"));
assertTrue(e.getResult().getStderr().contains("Schema not found"));
}
}

Expand Down

0 comments on commit 36f151c

Please sign in to comment.