Skip to content
This repository has been archived by the owner on Feb 27, 2021. It is now read-only.

Commit

Permalink
refactored code to use a single method for throwing exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Jun 25, 2018
1 parent 9104609 commit 276ca21
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/main/java/com/erudika/para/search/ElasticSearchUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,31 +335,32 @@ public void onResponse(BulkResponse bulkResponse) {
indexDocumentFailedCount();
});

if (Config.getConfigBoolean("es.fail_on_indexing_errors", false)) {
Throwable cause = Arrays.stream(bulkResponse.getItems()) //
handleFailedRequests(Arrays.stream(bulkResponse.getItems()) //
.filter(BulkItemResponse::isFailed) //
.map(BulkItemResponse::getFailure) //
.map(BulkItemResponse.Failure::getCause) //
.filter(Objects::nonNull) //
.findFirst().orElse(null);
throw new RuntimeException("Synchronous indexing operation failed", cause);
}
.findFirst().orElse(null));
}
}

@Override
public void onFailure(Exception ex) {
logger.error("Synchronous indexing operation failed", ex);
logger.error("Synchronous indexing operation failed!", ex);
indexRequestFailedCount();
if (Config.getConfigBoolean("es.fail_on_indexing_errors", false)) {
throw new RuntimeException("Synchronous indexing operation failed", ex);
}
handleFailedRequests(ex);
}
};

return syncListener;
}

private static void handleFailedRequests(Throwable t) {
if (t != null && Config.getConfigBoolean("es.fail_on_indexing_errors", false)) {
throw new RuntimeException("Synchronous indexing operation failed!", t);
}
}

/**
* Increment a count on the number of individual documents that failed in an indexing operation.
*/
Expand Down

0 comments on commit 276ca21

Please sign in to comment.