Skip to content

Commit 55d04ee

Browse files
committed
Fix create docs on error
1 parent d354985 commit 55d04ee

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Database/Database.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3827,6 +3827,7 @@ public function createDocument(string $collection, Document $document): Document
38273827
* @param array<Document> $documents
38283828
* @param int $batchSize
38293829
* @param (callable(Document): void)|null $onNext
3830+
* @param (callable(Throwable): void)|null $onError
38303831
* @return int
38313832
* @throws AuthorizationException
38323833
* @throws StructureException
@@ -3838,6 +3839,7 @@ public function createDocuments(
38383839
array $documents,
38393840
int $batchSize = self::INSERT_BATCH_SIZE,
38403841
?callable $onNext = null,
3842+
?callable $onError = null,
38413843
): int {
38423844
if (!$this->adapter->getSharedTables() && $this->adapter->getTenantPerDocument()) {
38433845
throw new DatabaseException('Shared tables must be enabled if tenant per document is enabled.');
@@ -3914,7 +3916,13 @@ public function createDocuments(
39143916

39153917
$document = $this->casting($collection, $document);
39163918
$document = $this->decode($collection, $document);
3917-
$onNext && $onNext($document);
3919+
3920+
try {
3921+
$onNext && $onNext($document);
3922+
} catch (\Throwable $e) {
3923+
$onError ? $onError($e) : throw $e;
3924+
}
3925+
39183926
$modified++;
39193927
}
39203928
}

0 commit comments

Comments
 (0)