Skip to content

Commit d76d609

Browse files
committed
Handle exceptions in InvoiceCreator while ensuring consistent flow
1 parent fe341c1 commit d76d609

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/Creator/InvoiceCreator.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,17 @@ public function __invoke(string $orderNumber, \DateTimeInterface $dateTime): voi
4949

5050
$invoice = $this->invoiceGenerator->generateForOrder($order, $dateTime);
5151

52-
if (!$this->hasEnabledPdfFileGenerator) {
52+
try {
5353
$this->invoiceRepository->add($invoice);
54+
} catch (\Throwable) {
55+
return;
56+
}
5457

58+
if (!$this->hasEnabledPdfFileGenerator) {
5559
return;
5660
}
5761

5862
$invoicePdf = $this->invoicePdfFileGenerator->generate($invoice);
5963
$this->invoiceFileManager->save($invoicePdf);
60-
61-
try {
62-
$this->invoiceRepository->add($invoice);
63-
} catch (ORMException) {
64-
$this->invoiceFileManager->remove($invoicePdf);
65-
}
6664
}
6765
}

0 commit comments

Comments
 (0)