Skip to content

Commit b45fe8d

Browse files
authored
Merge pull request #1777 from marklogic/feature/better-pdc-exception
Added better errors for PDC connection / auth issues
2 parents e58b677 + 17a32ef commit b45fe8d

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright © 2025 MarkLogic Corporation. All Rights Reserved.
3+
*/
4+
package com.marklogic.client;
5+
6+
/**
7+
* Added in 7.2.0 to more easily identify runtime exceptions pertaining to issues with connecting and/or
8+
* authenticating with ProgressDataCloud.
9+
*
10+
* @since 7.2.0
11+
*/
12+
public class ProgressDataCloudException extends RuntimeException {
13+
14+
public ProgressDataCloudException(String message) {
15+
super(message);
16+
}
17+
18+
public ProgressDataCloudException(String message, Throwable cause) {
19+
super(message, cause);
20+
}
21+
}

marklogic-client-api/src/main/java/com/marklogic/client/impl/okhttp/ProgressDataCloudAuthenticationConfigurer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.fasterxml.jackson.databind.JsonNode;
77
import com.fasterxml.jackson.databind.ObjectMapper;
88
import com.marklogic.client.DatabaseClientFactory;
9+
import com.marklogic.client.ProgressDataCloudException;
910
import okhttp3.*;
1011
import org.slf4j.Logger;
1112
import org.slf4j.LoggerFactory;
@@ -83,7 +84,7 @@ private Response callTokenEndpoint() {
8384
try {
8485
return call.execute();
8586
} catch (IOException e) {
86-
throw new RuntimeException(String.format("Unable to call token endpoint at %s; cause: %s",
87+
throw new ProgressDataCloudException(String.format("Unable to call token endpoint at %s; cause: %s",
8788
tokenUrl, e.getMessage(), e));
8889
}
8990
}
@@ -118,10 +119,10 @@ private String getAccessTokenFromResponse(Response response) {
118119
responseBody = response.body().string();
119120
payload = new ObjectMapper().readTree(responseBody);
120121
} catch (IOException ex) {
121-
throw new RuntimeException("Unable to get access token; response: " + responseBody, ex);
122+
throw new ProgressDataCloudException("Unable to get access token; response: " + responseBody, ex);
122123
}
123124
if (!payload.has("access_token")) {
124-
throw new RuntimeException("Unable to get access token; unexpected JSON response: " + payload);
125+
throw new ProgressDataCloudException("Unable to get access token; unexpected JSON response: " + payload);
125126
}
126127
return payload.get("access_token").asText();
127128
}

0 commit comments

Comments
 (0)