Skip to content
Snippets Groups Projects

Issue #3263786: Catch and log errors when a transaction update ails

2 files
+ 32
2
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -5,6 +5,7 @@ namespace Drupal\commerce_transaction\Updater;
use Drupal\commerce_payment\Plugin\Commerce\PaymentType\PaymentTypeInterface;
use Drupal\commerce_transaction\Entity\TransactionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Psr\Log\LoggerInterface;
/**
* The default transaction updater manager.
@@ -18,14 +19,27 @@ class UpdateManager implements UpdateManagerInterface {
*/
protected $entityTypeManager;
/**
* The module's logger.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* Constructs a new Installer object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Psr\Log\LoggerInterface $logger
* The module's logger.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
LoggerInterface $logger
) {
$this->entityTypeManager = $entity_type_manager;
$this->logger = $logger;
}
/**
@@ -90,7 +104,22 @@ class UpdateManager implements UpdateManagerInterface {
$transactions = $storage->loadMultiple($transaction_ids);
foreach ($transactions as $transaction) {
$this->doUpdateTransaction($payment_type, $transaction);
// We catch and log errors so that we can proceed and update other
// transactions. Otherwise all transactions could be prevented from
// getting updated when a single transaction fails for some reason.
try {
$this->doUpdateTransaction($payment_type, $transaction);
}
catch (\Throwable $throwable) {
$this->logger->error(
'An error occurred while updating the transaction with ID "%transaction_id". Error type: "%error_type". Error message: @message.',
[
'%transaction_id' => $transaction->id(),
'%error_type' => get_class($throwable),
'@message' => $throwable->getMessage(),
]
);
}
}
}
Loading