Skip to content

Commit 3e0a88a

Browse files
authored
Throw duplicate exception from an update method
1 parent f344f93 commit 3e0a88a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

document-store/src/main/java/org/hypertrace/core/documentstore/mongo/MongoCollection.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,28 @@ public Optional<Document> update(
558558
final java.util.Collection<SubDocumentUpdate> updates,
559559
final org.hypertrace.core.documentstore.model.options.UpdateOptions updateOptions)
560560
throws IOException {
561-
return updateExecutor.update(query, updates, updateOptions);
561+
try {
562+
return updateExecutor.update(query, updates, updateOptions);
563+
} catch (final MongoWriteException e) {
564+
if (e.getCode() == MONGODB_DUPLICATE_KEY_ERROR_CODE) {
565+
throw new DuplicateDocumentException();
566+
}
567+
LOGGER.error(
568+
"Exception updating document(s). query: {} updates:{} options:{}",
569+
query,
570+
updates,
571+
updateOptions,
572+
e);
573+
throw new IOException(e);
574+
} catch (final Exception e) {
575+
LOGGER.error(
576+
"Exception updating document(s). query: {} updates:{} options:{}",
577+
query,
578+
updates,
579+
updateOptions,
580+
e);
581+
throw new IOException(e);
582+
}
562583
}
563584

564585
@Override

0 commit comments

Comments
 (0)