diff options
author | Jon Bratseth <bratseth@gmail.com> | 2020-04-13 20:09:31 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2020-04-13 20:09:31 +0200 |
commit | 021feb4347cbf5a9954c60bd9d4ff9e286aa81e4 (patch) | |
tree | f1001abb6fd38be27b9c364e6d64e516935e2ed0 /vespaclient-container-plugin | |
parent | e40c993de0b870a2aec7fff91a64ac229b36fd0b (diff) |
Improve error messages
Diffstat (limited to 'vespaclient-container-plugin')
2 files changed, 16 insertions, 13 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java index 0485689b15d..1224e668bc0 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/OperationHandlerImpl.java @@ -35,6 +35,7 @@ import java.time.Instant; import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; /** * Sends operations to messagebus via document api. @@ -352,12 +353,16 @@ public class OperationHandlerImpl implements OperationHandler { protected static ClusterDef resolveClusterDef(Optional<String> wantedCluster, List<ClusterDef> clusters) throws RestApiException { if (clusters.size() == 0) { throw new IllegalArgumentException("Your Vespa cluster does not have any content clusters " + - "declared. Visiting feature is not available."); + "declared. Visiting feature is not available."); } if (! wantedCluster.isPresent()) { if (clusters.size() != 1) { - throw new RestApiException(Response.createErrorResponse(400, "Several clusters exist: " + - clusterListToString(clusters) + " you must specify one. ", RestUri.apiErrorCodes.SEVERAL_CLUSTERS)); + String message = "Several clusters exist: " + + clusters.stream().map(c -> "'" + c.getName() + "'").collect(Collectors.joining(", ")) + + ". You must specify one."; + throw new RestApiException(Response.createErrorResponse(400, + message, + RestUri.apiErrorCodes.SEVERAL_CLUSTERS)); } return clusters.get(0); } @@ -367,20 +372,18 @@ public class OperationHandlerImpl implements OperationHandler { return clusterDef; } } - throw new RestApiException(Response.createErrorResponse(400, "Your vespa cluster contains the content clusters " + - clusterListToString(clusters) + " not " + wantedCluster.get() + ". Please select a valid vespa cluster.", RestUri.apiErrorCodes.MISSING_CLUSTER)); + String message = "Your vespa cluster contains the content clusters " + + clusters.stream().map(c -> "'" + c.getName() + "'").collect(Collectors.joining(", ")) + + ", not '" + wantedCluster.get() + "'. Please select a valid vespa cluster."; + throw new RestApiException(Response.createErrorResponse(400, + message, + RestUri.apiErrorCodes.MISSING_CLUSTER)); } protected static String clusterDefToRoute(ClusterDef clusterDef) { return "[Storage:cluster=" + clusterDef.getName() + ";clusterconfigid=" + clusterDef.getConfigId() + "]"; } - private static String clusterListToString(List<ClusterDef> clusters) { - StringBuilder clusterListString = new StringBuilder(); - clusters.forEach(x -> clusterListString.append(x.getName()).append(" (").append(x.getConfigId()).append("), ")); - return clusterListString.toString(); - } - private static String buildAugmentedDocumentSelection(RestUri restUri, String documentSelection) { if (restUri.isRootOnly()) { return documentSelection; // May be empty, that's fine. diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/OperationHandlerImplTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/OperationHandlerImplTest.java index 4e5092cd416..bda49ecd3f5 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/OperationHandlerImplTest.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/OperationHandlerImplTest.java @@ -94,8 +94,8 @@ public class OperationHandlerImplTest { assertThat(e.getResponse().getStatus(), is(400)); String errorMsg = renderRestApiExceptionAsString(e); assertThat(errorMsg, is("{\"errors\":[{\"description\":" + - "\"MISSING_CLUSTER Your vespa cluster contains the content clusters foo2 (configId2), foo (configId)," + - " foo3 (configId2), not wrong. Please select a valid vespa cluster.\",\"id\":-9}]}")); + "\"MISSING_CLUSTER Your vespa cluster contains the content clusters 'foo2', 'foo'," + + " 'foo3', not 'wrong'. Please select a valid vespa cluster.\",\"id\":-9}]}")); return; } fail("Expected exception"); |