diff options
Diffstat (limited to 'vespaclient-container-plugin/src')
11 files changed, 103 insertions, 56 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 4387f975d01..3d664d87622 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 @@ -70,16 +70,25 @@ public class OperationHandlerImpl implements OperationHandler { private static final int HTTP_STATUS_BAD_REQUEST = 400; private static final int HTTP_STATUS_INSUFFICIENT_STORAGE = 507; + private static final int HTTP_PRE_CONDIDTION_FAILED = 412; - private static int getHTTPStatusCode(Set<Integer> errorCodes) { - if (errorCodes.size() == 1 && errorCodes.contains(DocumentProtocol.ERROR_NO_SPACE)) { + private static int getHTTPStatusCode(DocumentAccessException documentException) { + if (documentException.getErrorCodes().size() == 1 && documentException.getErrorCodes().contains(DocumentProtocol.ERROR_NO_SPACE)) { return HTTP_STATUS_INSUFFICIENT_STORAGE; } + if (documentException.hasConditionNotMetError()) { + return HTTP_PRE_CONDIDTION_FAILED; + } return HTTP_STATUS_BAD_REQUEST; } private static Response createErrorResponse(DocumentAccessException documentException, RestUri restUri) { - return Response.createErrorResponse(getHTTPStatusCode(documentException.getErrorCodes()), documentException.getMessage(), restUri); + if (documentException.hasConditionNotMetError()) { + return Response.createErrorResponse(getHTTPStatusCode(documentException), "Condition did not match document.", + restUri, RestUri.apiErrorCodes.DOCUMENT_CONDITION_NOT_MET); + } + return Response.createErrorResponse(getHTTPStatusCode(documentException), documentException.getMessage(), restUri, + RestUri.apiErrorCodes.DOCUMENT_EXCPETION); } @Override @@ -105,7 +114,8 @@ public class OperationHandlerImpl implements OperationHandler { throw new RestApiException(Response.createErrorResponse( 500, "Failed during parsing of arguments for visiting: " + ExceptionUtils.getStackTrace(e), - restUri)); + restUri, + RestUri.apiErrorCodes.VISITOR_ERROR)); } try { return doVisit(visitorControlHandler, localDataVisitorHandler, restUri); @@ -120,13 +130,13 @@ public class OperationHandlerImpl implements OperationHandler { RestUri restUri) throws RestApiException { try { if (! visitorControlHandler.waitUntilDone(VISIT_TIMEOUT_MS)) { - throw new RestApiException(Response.createErrorResponse(500, "Timed out", restUri)); + throw new RestApiException(Response.createErrorResponse(500, "Timed out", restUri, RestUri.apiErrorCodes.TIME_OUT)); } if (visitorControlHandler.getResult().code != VisitorControlHandler.CompletionCode.SUCCESS) { - throw new RestApiException(Response.createErrorResponse(400, visitorControlHandler.getResult().toString())); + throw new RestApiException(Response.createErrorResponse(400, visitorControlHandler.getResult().toString(), RestUri.apiErrorCodes.VISITOR_ERROR)); } } catch (InterruptedException e) { - throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri)); + throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.INTERRUPTED)); } if (localDataVisitorHandler.getErrors().isEmpty()) { final Optional<String> continuationToken; @@ -138,14 +148,14 @@ public class OperationHandlerImpl implements OperationHandler { } return new VisitResult(continuationToken, localDataVisitorHandler.getCommaSeparatedJsonDocuments()); } - throw new RestApiException(Response.createErrorResponse(500, localDataVisitorHandler.getErrors(), restUri)); + throw new RestApiException(Response.createErrorResponse(500, localDataVisitorHandler.getErrors(), restUri, RestUri.apiErrorCodes.UNSPECIFIED)); } private void setRoute(SyncSession session, Optional<String> route) throws RestApiException { if (! (session instanceof MessageBusSyncSession)) { // Not sure if this ever could happen but better be safe. throw new RestApiException(Response.createErrorResponse( - 400, "Can not set route since the API is not using message bus.")); + 400, "Can not set route since the API is not using message bus.", RestUri.apiErrorCodes.NO_ROUTE_WHEN_NOT_PART_OF_MESSAGEBUS)); } ((MessageBusSyncSession) session).setRoute(route.orElse("default")); } @@ -161,7 +171,7 @@ public class OperationHandlerImpl implements OperationHandler { } catch (DocumentAccessException documentException) { throw new RestApiException(createErrorResponse(documentException, restUri)); } catch (Exception e) { - throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri)); + throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.INTERNAL_EXCEPTION)); } finally { syncSessions.free(syncSession); } @@ -176,7 +186,7 @@ public class OperationHandlerImpl implements OperationHandler { } catch (DocumentAccessException documentException) { throw new RestApiException(createErrorResponse(documentException, restUri)); } catch (Exception e) { - throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri)); + throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.INTERNAL_EXCEPTION)); } finally { syncSessions.free(syncSession); } @@ -194,9 +204,13 @@ public class OperationHandlerImpl implements OperationHandler { } syncSession.remove(documentRemove); } catch (DocumentAccessException documentException) { - throw new RestApiException(Response.createErrorResponse(400, documentException.getMessage(), restUri)); + if (documentException.hasConditionNotMetError()) { + throw new RestApiException(Response.createErrorResponse(412, "Condition not met: " + documentException.getMessage(), + restUri, RestUri.apiErrorCodes.DOCUMENT_CONDITION_NOT_MET)); + } + throw new RestApiException(Response.createErrorResponse(400, documentException.getMessage(), restUri, RestUri.apiErrorCodes.DOCUMENT_EXCPETION)); } catch (Exception e) { - throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri)); + throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.UNSPECIFIED)); } finally { syncSessions.free(syncSession); } @@ -218,7 +232,7 @@ public class OperationHandlerImpl implements OperationHandler { return Optional.of(outputStream.toString(StandardCharsets.UTF_8.name())); } catch (Exception e) { - throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri)); + throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.UNSPECIFIED)); } finally { syncSessions.free(syncSession); } @@ -238,7 +252,7 @@ public class OperationHandlerImpl implements OperationHandler { if (! wantedCluster.isPresent()) { if (clusters.size() != 1) { new RestApiException(Response.createErrorResponse(400, "Several clusters exist: " + - clusterListToString(clusters) + " you must specify one.. ")); + clusterListToString(clusters) + " you must specify one.. ", RestUri.apiErrorCodes.SEVERAL_CLUSTERS)); } return clusterDefToRoute(clusters.get(0)); } @@ -249,7 +263,7 @@ public class OperationHandlerImpl implements OperationHandler { } } throw new RestApiException(Response.createErrorResponse(400, "Your vespa cluster contains the content clusters " + - clusterListToString(clusters) + " not " + wantedCluster.get() + ". Please select a valid vespa cluster.")); + clusterListToString(clusters) + " not " + wantedCluster.get() + ". Please select a valid vespa cluster.", RestUri.apiErrorCodes.MISSING_CLUSTER)); } @@ -304,7 +318,7 @@ public class OperationHandlerImpl implements OperationHandler { try { params.setResumeToken(ContinuationHit.getToken(continuation.get())); } catch (Exception e) { - throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri)); + throw new RestApiException(Response.createErrorResponse(500, ExceptionUtils.getStackTrace(e), restUri, RestUri.apiErrorCodes.UNSPECIFIED)); } } return params; diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/Response.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/Response.java index 9c846e9ce38..cbc816b4e09 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/Response.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/Response.java @@ -25,16 +25,18 @@ public class Response extends HttpResponse { jsonMessage = objectNode.toString(); } - public static Response createErrorResponse(int code, String errorMessage) { - ObjectNode objectNode = objectMapper.createObjectNode(); - objectNode.putArray("errors").add(errorMessage); - return new Response(code, Optional.of(objectNode), Optional.<RestUri>empty()); + public static Response createErrorResponse(int code, String errorMessage, RestUri.apiErrorCodes errorID) { + return createErrorResponse(code, errorMessage, null, errorID); } - public static Response createErrorResponse(int code, String errorMessage, RestUri restUri) { + public static Response createErrorResponse(int code, String errorMessage, RestUri restUri, RestUri.apiErrorCodes errorID) { + ObjectNode errorNode = objectMapper.createObjectNode(); + errorNode.put("description", errorID.name() + " " + errorMessage); + errorNode.put("id", errorID.value); + ObjectNode objectNode = objectMapper.createObjectNode(); - objectNode.putArray("errors").add(errorMessage); - return new Response(code, Optional.of(objectNode), Optional.of(restUri)); + objectNode.putArray("errors").add(errorNode); + return new Response(code, Optional.of(objectNode), Optional.ofNullable(restUri)); } @Override diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/RestUri.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/RestUri.java index f50e7c247b1..7b6bc4e87c5 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/RestUri.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/RestUri.java @@ -25,6 +25,30 @@ public class RestUri { public static final String V_1 = "v1"; public static final String ID = "id:"; + public enum apiErrorCodes { + ERROR_ID_BASIC_USAGE(-1), + ERROR_ID_DECODING_PATH(-2), + VISITOR_ERROR(-3), + NO_ROUTE_WHEN_NOT_PART_OF_MESSAGEBUS(-4), + SEVERAL_CLUSTERS(-5), + URL_PARSING(-6), + INVALID_CREATE_VALUE(-7), + TOO_MANY_PARALLEL_REQUESTS(-8), + MISSING_CLUSTER(-9), INTERNAL_EXCEPTION(-9), + DOCUMENT_CONDITION_NOT_MET(-10), + DOCUMENT_EXCPETION(-11), + PARSER_ERROR(-11), + GROUP_AND_EXPRESSION_ERROR(-12), + TIME_OUT(-13), + INTERRUPTED(-14), + UNSPECIFIED(-15); + + public final long value; + apiErrorCodes(long value) { + this.value = value; + } + } + /** * Represents the "grouping" part of document id which can be used with streaming model. */ @@ -69,6 +93,7 @@ public class RestUri { } static class PathParser { + public static final long ERROR_ID_DECODING_PATH = -10L; final List<String> rawParts; final String originalPath; int readPos = 0; @@ -88,7 +113,7 @@ public class RestUri { try { return URLDecoder.decode(rawId, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { - throw new RestApiException(Response.createErrorResponse(BAD_REQUEST,"Problems decoding the URI: " + e.getMessage())); + throw new RestApiException(Response.createErrorResponse(BAD_REQUEST,"Problems decoding the URI: " + e.getMessage(), apiErrorCodes.ERROR_ID_DECODING_PATH)); } } } @@ -119,9 +144,9 @@ public class RestUri { private static void throwUsage(String inputPath) throws RestApiException { throw new RestApiException(Response.createErrorResponse(BAD_REQUEST, - "Expected:\n" + - ".../{namespace}/{document-type}/group/{name}/[{user-specified}]\n" + - ".../{namespace}/{document-type}/docid/[{user-specified}]\n: but got " + inputPath)); + "Expected: " + + ".../{namespace}/{document-type}/group/{name}/[{user-specified}] " + + ".../{namespace}/{document-type}/docid/[{user-specified}] : but got " + inputPath, apiErrorCodes.ERROR_ID_BASIC_USAGE)); } } diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java index fba32f5c1fd..66e8c6475aa 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/RestApi.java @@ -114,7 +114,7 @@ public class RestApi extends LoggingRequestHandler { if (threadsAvailableForApi.decrementAndGet() < 1) { return Response.createErrorResponse( 429 /* Too Many Requests */, - "Too many parallel requests, consider using http-vespa-java-client. Please try again later."); + "Too many parallel requests, consider using http-vespa-java-client. Please try again later.", RestUri.apiErrorCodes.TOO_MANY_PARALLEL_REQUESTS); } return handleInternal(request); } finally { @@ -130,13 +130,13 @@ public class RestApi extends LoggingRequestHandler { } catch (RestApiException e) { return e.getResponse(); } catch (Exception e2) { - return Response.createErrorResponse(500, "Exception while parsing URI: " + e2.getMessage()); + return Response.createErrorResponse(500, "Exception while parsing URI: " + e2.getMessage(), RestUri.apiErrorCodes.URL_PARSING); } Optional<Boolean> create = parseBoolean(CREATE_PARAMETER_NAME, request); if (create == null) { return Response.createErrorResponse(403, "Non valid value for 'create' parameter, must be empty, true, or " + - "false: " + request.getProperty(CREATE_PARAMETER_NAME)); + "false: " + request.getProperty(CREATE_PARAMETER_NAME), RestUri.apiErrorCodes.INVALID_CREATE_VALUE); } String condition = request.getProperty(CONDITION_PARAMETER_NAME); Optional<String> route = Optional.ofNullable(request.getProperty(ROUTE_PARAMETER_NAME)); @@ -163,7 +163,7 @@ public class RestApi extends LoggingRequestHandler { } catch (Exception e2) { // We always blame the user. This might be a bit nasty, but the parser throws various kind of exception // types, but with nice descriptions. - return Response.createErrorResponse(400, e2.getMessage(), restUri); + return Response.createErrorResponse(400, e2.getMessage(), restUri, RestUri.apiErrorCodes.PARSER_ERROR); } return new Response(200, resultJson, Optional.of(restUri)); } @@ -221,7 +221,8 @@ public class RestApi extends LoggingRequestHandler { return Response.createErrorResponse( 400, "Visiting does not support setting value for group/value in combination with expression, try using only expression parameter instead.", - restUri); + restUri, + RestUri.apiErrorCodes.GROUP_AND_EXPRESSION_ERROR); } RestUri.Group group = restUri.getGroup().get(); if (group.name == 'n') { diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/ClientFeederV3.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/ClientFeederV3.java index 301b81f040c..f91038a0a79 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/ClientFeederV3.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/ClientFeederV3.java @@ -154,7 +154,7 @@ class ClientFeederV3 { + Exceptions.toMessageString(e), e); } finally { try { - replies.add(createOperationStatus("-", "-", ErrorCode.END_OF_FEED, null)); + replies.add(createOperationStatus("-", "-", ErrorCode.END_OF_FEED, false, null)); } catch (InterruptedException e) { // NOP, we are already exiting the thread } @@ -196,7 +196,7 @@ class ClientFeederV3 { log.log(LogLevel.DEBUG, Exceptions.toMessageString(e), e); } repliesFromOldMessages.add(new OperationStatus( - Exceptions.toMessageString(e), operationId.get(), ErrorCode.ERROR, "")); + Exceptions.toMessageString(e), operationId.get(), ErrorCode.ERROR, false, "")); continue; } @@ -246,7 +246,7 @@ class ClientFeederV3 { } catch (RuntimeException e) { repliesFromOldMessages.add(createOperationStatus(msg.get().getOperationId(), Exceptions.toMessageString(e), - ErrorCode.ERROR, msg.get().getMessage())); + ErrorCode.ERROR, false, msg.get().getMessage())); continue; } @@ -256,24 +256,25 @@ class ClientFeederV3 { log(LogLevel.DEBUG, "Sent message successfully, document id: ", msg.get().getOperationId()); } else if (!result.getError().isFatal()) { repliesFromOldMessages.add(createOperationStatus(msg.get().getOperationId(), result.getError().getMessage(), - ErrorCode.TRANSIENT_ERROR, msg.get().getMessage())); + ErrorCode.TRANSIENT_ERROR, false, msg.get().getMessage())); continue; } else { // should probably not happen, but everybody knows stuff that // shouldn't happen, happens all the time + boolean isConditionNotMet = result.getError().getCode() == DocumentProtocol.ERROR_TEST_AND_SET_CONDITION_FAILED; repliesFromOldMessages.add(createOperationStatus(msg.get().getOperationId(), result.getError().getMessage(), - ErrorCode.ERROR, msg.get().getMessage())); + ErrorCode.ERROR, isConditionNotMet, msg.get().getMessage())); continue; } } } - private OperationStatus createOperationStatus(String id, String message, ErrorCode code, Message msg) + private OperationStatus createOperationStatus(String id, String message, ErrorCode code, boolean isConditionNotMet, Message msg) throws InterruptedException { String traceMessage = msg != null && msg.getTrace() != null && msg.getTrace().getLevel() > 0 ? msg.getTrace().toString() : ""; - return new OperationStatus(message, id, code, traceMessage); + return new OperationStatus(message, id, code, isConditionNotMet, traceMessage); } // protected for mocking diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedReplyReader.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedReplyReader.java index f22e25dd577..26dc97c5c65 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedReplyReader.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedReplyReader.java @@ -3,6 +3,7 @@ package com.yahoo.vespa.http.server; import java.util.logging.Logger; +import com.yahoo.documentapi.messagebus.protocol.DocumentProtocol; import com.yahoo.jdisc.Metric; import com.yahoo.log.LogLevel; import com.yahoo.messagebus.Reply; @@ -38,17 +39,19 @@ public class FeedReplyReader implements ReplyHandler { null); if (reply.hasErrors()) { metric.add(MetricNames.FAILED, 1, null); - enqueue(context, reply.getError(0).getMessage(), ErrorCode.ERROR, reply.getTrace()); + enqueue(context, reply.getError(0).getMessage(), ErrorCode.ERROR, + reply.getError(0).getCode() == DocumentProtocol.ERROR_TEST_AND_SET_CONDITION_FAILED, reply.getTrace()); } else { metric.add(MetricNames.SUCCEEDED, 1, null); - enqueue(context, "Document processed.", ErrorCode.OK, reply.getTrace()); + enqueue(context, "Document processed.", ErrorCode.OK, false, reply.getTrace()); } } - private void enqueue(ReplyContext context, String message, ErrorCode status, Trace trace) { + private void enqueue(ReplyContext context, String message, ErrorCode status, boolean isConditionNotMet, Trace trace) { try { String traceMessage = (trace != null && trace.getLevel() > 0) ? trace.toString() : ""; - context.feedReplies.put(new OperationStatus(message, context.docId, status, traceMessage)); + + context.feedReplies.put(new OperationStatus(message, context.docId, status, isConditionNotMet, traceMessage)); } catch (InterruptedException e) { log.log(LogLevel.WARNING, "Interrupted while enqueueing result from putting document with id: " + context.docId); diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/Feeder.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/Feeder.java index b361dc22d95..ad773519458 100644 --- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/Feeder.java +++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/Feeder.java @@ -184,7 +184,7 @@ public class Feeder implements Runnable { requestReceived.countDown(); putClient(); try { - enqueue("-", "-", ErrorCode.END_OF_FEED, null); + enqueue("-", "-", ErrorCode.END_OF_FEED, false, null); } catch (InterruptedException e) { // NOP, we are already exiting the thread } @@ -252,7 +252,7 @@ public class Feeder implements Runnable { } } catch (RuntimeException e) { enqueue(msg.first, Exceptions.toMessageString(e), - ErrorCode.ERROR, msg.second); + ErrorCode.ERROR, false, msg.second); return; } if (result.isAccepted() || result.getError().getCode() != SEND_QUEUE_FULL) { @@ -272,12 +272,13 @@ public class Feeder implements Runnable { updateOpsPerSec(); log(LogLevel.DEBUG, "Sent message successfully, document id: ", msg.first); } else if (!result.getError().isFatal()) { - enqueue(msg.first, result.getError().getMessage(), ErrorCode.TRANSIENT_ERROR, msg.second); + enqueue(msg.first, result.getError().getMessage(), ErrorCode.TRANSIENT_ERROR, false, msg.second); break; } else { // should probably not happen, but everybody knows stuff that // shouldn't happen, happens all the time - enqueue(msg.first, result.getError().getMessage(), ErrorCode.ERROR, msg.second); + boolean isConditionNotMet = result.getError().getCode() == DocumentProtocol.ERROR_TEST_AND_SET_CONDITION_FAILED; + enqueue(msg.first, result.getError().getMessage(), ErrorCode.ERROR, isConditionNotMet, msg.second); break; } } @@ -487,12 +488,12 @@ public class Feeder implements Runnable { --numPending; } - private void enqueue(String id, String message, ErrorCode code, Message msg) + private void enqueue(String id, String message, ErrorCode code, boolean isConditionalNotMet, Message msg) throws InterruptedException { String traceMessage = msg != null && msg.getTrace() != null && msg.getTrace().getLevel() > 0 ? msg.getTrace().toString() : ""; - operations.put(new OperationStatus(message, id, code, traceMessage)); + operations.put(new OperationStatus(message, id, code, isConditionalNotMet, traceMessage)); } public void waitForRequestReceived() throws InterruptedException { 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 87360fcf998..8b7276441f2 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 @@ -66,8 +66,9 @@ public class OperationHandlerImplTest { ByteArrayOutputStream stream = new ByteArrayOutputStream(); e.getResponse().render(stream); String errorMsg = new String( stream.toByteArray()); - assertThat(errorMsg, is("{\"errors\":[\"Your vespa cluster contains the content clusters foo2 " + - "(configId2), foo (configId), foo3 (configId2), not wrong. Please select a valid vespa cluster.\"]}")); + 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}]}")); return; } fail("Expected exception"); diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java index 2d98b72e579..f4f745fbcee 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java @@ -45,7 +45,7 @@ public class MockedOperationHandler implements OperationHandler { String theLog = log.toString(); log = new StringBuilder(); deleteCount = 0; - throw new RestApiException(Response.createErrorResponse(666, theLog)); + throw new RestApiException(Response.createErrorResponse(666, theLog, RestUri.apiErrorCodes.ERROR_ID_BASIC_USAGE)); } log.append("DELETE: " + restUri.generateFullId()); } diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/RestApiTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/RestApiTest.java index 3971b4320b5..ecaaba77435 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/RestApiTest.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/RestApiTest.java @@ -96,7 +96,6 @@ public class RestApiTest { assertThat(x, is(post_test_response_cond)); } - String post_test_empty_response = "{\"errors\":[\"Could not read document, no document?\"]"; @Test public void testEmptyPost() throws Exception { Request request = new Request("http://localhost:" + getFirstListenPort() + post_test_uri); @@ -104,7 +103,7 @@ public class RestApiTest { StringEntity entity = new StringEntity("", ContentType.create("application/json")); httpPost.setEntity(entity); String x = doRest(httpPost); - assertThat(x, startsWith(post_test_empty_response)); + assertThat(x, containsString("Could not read document, no document?")); } String update_test_uri = "/document/v1/namespace/testdocument/docid/c"; diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/feedhandler/v3/FeedTesterV3.java b/vespaclient-container-plugin/src/test/java/com/yahoo/feedhandler/v3/FeedTesterV3.java index 708a9ed7a6b..7e5ac4dff3a 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/feedhandler/v3/FeedTesterV3.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/feedhandler/v3/FeedTesterV3.java @@ -111,7 +111,7 @@ public class FeedTesterV3 { Object[] args = invocation.getArguments(); PutDocumentMessage putDocumentMessage = (PutDocumentMessage) args[0]; ReplyContext replyContext = (ReplyContext)putDocumentMessage.getContext(); - replyContext.feedReplies.add(new OperationStatus("message", replyContext.docId, ErrorCode.OK, "trace")); + replyContext.feedReplies.add(new OperationStatus("message", replyContext.docId, ErrorCode.OK, false, "trace")); Result result = mock(Result.class); when(result.isAccepted()).thenReturn(true); return result; |