Skip to content

Commit

Permalink
Added diagnostics to cover potential problems when using GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidCroftDKFZ committed Nov 18, 2024
1 parent c0b4b3b commit be9e7df
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>de.samply</groupId>
<artifactId>directory_sync_service</artifactId>
<version>1.5.4</version>
<version>1.5.5</version>
<name>directory_sync_service</name>
<description>Directory sync</description>
<url>https://github.com/samply/directory_sync_service</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public boolean endpointExists(String endpoint) {
protected String executeRequest(HttpUriRequest request) {
String result = null;
try {
logger.debug("executeRequest: execute request" );
CloseableHttpResponse response = httpClient.execute(request);
logger.debug("executeRequest: request executed" );
if (response.getStatusLine().getStatusCode() < 300) {
HttpEntity httpEntity = response.getEntity();
if (httpEntity == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static boolean merge(DirectoryCollectionGet directoryCollectionGet, Direc
* @return The DirectoryCollectionPut object with merged data, or null if an exception occurs.
*/
private static DirectoryCollectionPut merge(String collectionId, DirectoryCollectionGet directoryCollectionGet, DirectoryCollectionPut directoryCollectionPut) {
logger.info("Merging DirectoryCollectionGet into DirectoryCollectionPut for collectionId: " + collectionId);
logger.debug("Merging DirectoryCollectionGet into DirectoryCollectionPut for collectionId: " + collectionId);
try {
directoryCollectionPut.setName(collectionId, directoryCollectionGet.getName(collectionId));
directoryCollectionPut.setDescription(collectionId, directoryCollectionGet.getDescription(collectionId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,25 @@ public boolean endpointIsValidGraphql(String endpoint) {
logger.debug("endpointIsValidGraphql: url: " + url);
HttpGet request = new HttpGet(url);

logger.debug("endpointIsValidGraphql: execute request");
String response = executeRequest(request);
logger.debug("endpointIsValidGraphql: finished executing request");
if (response == null) {
logger.warn("endpointIsValidGraphql: HTTP response is null");
return false;
}

try {
// Use gson to turn the response into a JSON object
logger.debug("endpointIsValidGraphql: turn response into JSON");
JsonObject jsonResponse = gson.fromJson(response, JsonObject.class);
if (jsonResponse == null) {
logger.warn("endpointIsValidGraphql: jsonResponse is null");
return false;
}

logger.debug("endpointIsValidGraphql: check response for error");

// Check if the response contains an error
if (jsonResponse.has("errors")) {
logger.warn("endpointIsValidGraphql: jsonResponse has the following errors:");
Expand All @@ -77,6 +82,8 @@ public boolean endpointIsValidGraphql(String endpoint) {
return false;
}

logger.debug("endpointIsValidGraphql: all good, returning true");

return true;
}

Expand Down

0 comments on commit be9e7df

Please sign in to comment.