Skip to content

Commit dd2e861

Browse files
authored
Merge pull request #1631 from marklogic/feature/update-error-message
Improved error message when Optic update plan fails
2 parents e324d60 + 0c9409e commit dd2e861

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

marklogic-client-api/src/main/java/com/marklogic/client/impl/RowManagerImpl.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@
3333
import com.fasterxml.jackson.databind.JsonNode;
3434
import com.fasterxml.jackson.databind.ObjectMapper;
3535
import com.fasterxml.jackson.databind.node.JsonNodeType;
36+
import com.marklogic.client.*;
3637
import com.marklogic.client.DatabaseClientFactory.HandleFactoryRegistry;
37-
import com.marklogic.client.MarkLogicBindingException;
38-
import com.marklogic.client.MarkLogicIOException;
39-
import com.marklogic.client.MarkLogicInternalException;
40-
import com.marklogic.client.Transaction;
4138
import com.marklogic.client.document.DocumentWriteSet;
4239
import com.marklogic.client.expression.PlanBuilder;
4340
import com.marklogic.client.expression.PlanBuilder.Plan;
@@ -422,11 +419,22 @@ private RESTServiceResultIterator submitPlan(PlanBuilderBaseImpl.RequestPlan req
422419
AbstractWriteHandle astHandle = requestPlan.getHandle();
423420
List<ContentParam> contentParams = requestPlan.getContentParams();
424421
final String path = determinePath();
425-
if (contentParams != null && !contentParams.isEmpty()) {
426-
contentParams.add(new ContentParam(new PlanBuilderBaseImpl.PlanParamBase("query"), astHandle, null));
427-
return services.postMultipartForm(requestLogger, path, transaction, params, contentParams);
428-
}
429-
return services.postIteratedResource(requestLogger, path, transaction, params, astHandle);
422+
try {
423+
if (contentParams != null && !contentParams.isEmpty()) {
424+
contentParams.add(new ContentParam(new PlanBuilderBaseImpl.PlanParamBase("query"), astHandle, null));
425+
return services.postMultipartForm(requestLogger, path, transaction, params, contentParams);
426+
}
427+
return services.postIteratedResource(requestLogger, path, transaction, params, astHandle);
428+
} catch (FailedRequestException ex) {
429+
String message = ex.getMessage();
430+
if (message != null && message.contains("RESTAPI-UPDATEFROMQUERY")) {
431+
String betterMessage = "The Optic plan is attempting an update but was sent to the wrong REST API endpoint. " +
432+
"You must invoke `withUpdate(true)` on the instance of com.marklogic.client.row.RowManager that you " +
433+
"are using to submit the plan";
434+
throw new FailedRequestException(betterMessage, ex.getFailedRequest());
435+
}
436+
throw ex;
437+
}
430438
}
431439

432440
private PlanBuilderBaseImpl.RequestPlan checkPlan(Plan plan) {

marklogic-client-api/src/test/java/com/marklogic/client/test/rows/LockForUpdateTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,18 @@ public void basicTest() {
6969
@Test
7070
void wrongEndpoint() {
7171
rowManager.withUpdate(false);
72-
assertThrows(
72+
FailedRequestException ex = assertThrows(
7373
FailedRequestException.class,
7474
() -> rowManager.execute(op.fromDocUris("/optic/test/musician1.json").lockForUpdate()),
7575
"Hoping to update this assertion to verify that the server message tells the user to hit v1/rows/update " +
7676
"instead; right now, it's mentioning using declareUpdate() which isn't applicable to a REST API user."
7777
);
78+
79+
assertTrue(ex.getMessage().contains(
80+
"The Optic plan is attempting an update but was sent to the wrong REST API endpoint. " +
81+
"You must invoke `withUpdate(true)` on the instance of com.marklogic.client.row.RowManager " +
82+
"that you are using to submit the plan."),
83+
"Unexpected message: " + ex.getMessage());
7884
}
7985

8086
@Test

0 commit comments

Comments
 (0)