Skip to content

Commit

Permalink
Add logs on failures
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanChernetskyi committed Jun 18, 2024
1 parent 88071bc commit 8aa13c5
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ private CompletableFuture<List<Item>> createItems(List<JsonObject> jsons, List<N
.map(item ->
itemCollection.add(item)
.exceptionally(e -> {
LOGGER.warn("createHoldings:: Error during creating item with id: {} for holdingsRecord with id: {}", item.getId(), item.getHoldingId(), e);
notUpdatedEntities.add(new NotUpdatedEntity().withEntityId(item.getHoldingId()).withErrorMessage(e.getMessage()));
throw new CompletionException(e);
}))
Expand All @@ -209,6 +210,7 @@ private CompletableFuture<List<HoldingsRecord>> createHoldings(List<JsonObject>
.map(holdingRecord ->
holdingsRecordCollection.add(holdingRecord)
.exceptionally(e -> {
LOGGER.warn("createHoldings:: Error during creating holdingsRecord with id: {}", holdingRecord.getId(), e);
notUpdatedEntities.add(new NotUpdatedEntity().withEntityId(holdingRecord.getId()).withErrorMessage(e.getMessage()));
throw new CompletionException(e);
}))
Expand All @@ -228,6 +230,9 @@ private CompletableFuture<List<String>> deleteHoldings(List<HoldingsRecord> hold
Promise<String> promise = Promise.promise();
holdingsRecordCollection.delete(holdingsRecord.getId(), success -> promise.complete(holdingsRecord.getId()),
failure -> {
LOGGER.warn("deleteHoldings:: Error during deleting holdingsRecord with id: {}, status code: {}, reason: {}",
holdingsRecord.getId(), failure.getStatusCode(), failure.getReason());

notUpdatedEntities.add(new NotUpdatedEntity().withEntityId(holdingsRecord.getId()).withErrorMessage(failure.getReason()));
promise.fail(failure.getReason());
});
Expand All @@ -247,6 +252,9 @@ private CompletableFuture<List<String>> deleteItems(List<Item> itemIds, List<Not
Promise<String> promise = Promise.promise();
itemCollection.delete(item.getId(), success -> promise.complete(item.getId()),
failure -> {
LOGGER.warn("deleteItems:: Error during deleting item with id: {} for holdingsRecord with id {}, status code: {}, reason: {}",
item.getId(), item.getHoldingId(), failure.getStatusCode(), failure.getReason());

notUpdatedEntities.add(new NotUpdatedEntity().withEntityId(item.getHoldingId()).withErrorMessage(failure.getReason()));
promise.fail(failure.getReason());
});
Expand All @@ -263,8 +271,11 @@ private CompletableFuture<List<String>> deleteItems(List<Item> itemIds, List<Not
private void processNotFoundedInstances(List<String> holdingsRecordIds, List<NotUpdatedEntity> notUpdatedEntities, WebContext context, List<JsonObject> jsons) {
List<String> foundedIds = jsons.stream().map(json -> json.getString("id")).toList();
List<String> notFoundedIds = ListUtils.subtract(holdingsRecordIds, foundedIds);
notFoundedIds.forEach(id ->
notUpdatedEntities.add(new NotUpdatedEntity().withEntityId(id).withErrorMessage(String.format(INSTANCE_NOT_FOUND, id, context.getTenantId()))));
notFoundedIds.forEach(id -> {
String errorMessage = String.format(INSTANCE_NOT_FOUND, id, context.getTenantId());
LOGGER.warn("processNotFoundedInstances:: " + errorMessage);
notUpdatedEntities.add(new NotUpdatedEntity().withEntityId(id).withErrorMessage(errorMessage));
});
}

private List<HoldingsRecord> getHoldingsToDelete(List<NotUpdatedEntity> notUpdatedEntities, List<HoldingsRecord> createdHoldings) {
Expand Down

0 comments on commit 8aa13c5

Please sign in to comment.