Skip to content

Commit dda6744

Browse files
authored
Merge pull request #1719 from BillFarber/task/fixInvokeErrorMessage
Invoke errors are now forced to be JSON.
2 parents 7b5b36a + 2a03602 commit dda6744

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4229,7 +4229,7 @@ private Request.Builder setErrorFormatIfNecessary(Request.Builder requestBuilder
42294229
// server defaults to 'compatible'. If the error format is 'compatible', a block of HTML is sent back which
42304230
// causes an error that prevents the user from seeing the actual error from the server. So for all eval calls,
42314231
// X-Error-Accept is used to request any errors back as JSON so that they can be handled correctly.
4232-
if ("eval".equals(path)) {
4232+
if ("eval".equals(path) || ("invoke".equals(path))) {
42334233
requestBuilder.addHeader(HEADER_ERROR_FORMAT, "application/json");
42344234
}
42354235
return requestBuilder;

marklogic-client-api/src/test/java/com/marklogic/client/test/EvalTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ void invalidJavascript() {
8585
"https://docs.marklogic.com/guide/rest-dev/intro#id_34966; actual error: " + message);
8686
}
8787

88+
@Test
89+
void invalidJavascriptModule() {
90+
FailedRequestException ex = assertThrows(FailedRequestException.class, () ->
91+
Common.evalClient.newServerEval().modulePath("/data/moduleDoesNotExist.sjs").eval()
92+
);
93+
String message = ex.getServerMessage();
94+
assertTrue(
95+
message.contains("Module /data/moduleDoesNotExist.sjs not found"),
96+
"The error message from the server is expected to contain the actual error, which in this case " +
97+
"is due to a missing module. In order for this to happen, the Java Client should send the " +
98+
"X-Error-Accept header per the docs at https://docs.marklogic.com/guide/rest-dev/intro#id_34966; " +
99+
"actual error: " + message);
100+
}
101+
88102
@Test
89103
void invalidXQuery() {
90104
FailedRequestException ex = assertThrows(FailedRequestException.class, () ->

0 commit comments

Comments
 (0)