From bc948ec092b508b24b33f1d186673961ebf5ea63 Mon Sep 17 00:00:00 2001 From: Iman Date: Tue, 26 Apr 2022 00:18:34 +0430 Subject: [PATCH] throw deadlock exception (#42129) --- Concerns/ManagesTransactions.php | 10 +++++++--- DeadlockException.php | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 DeadlockException.php diff --git a/Concerns/ManagesTransactions.php b/Concerns/ManagesTransactions.php index d8932d4ee..038e10477 100644 --- a/Concerns/ManagesTransactions.php +++ b/Concerns/ManagesTransactions.php @@ -3,6 +3,7 @@ namespace Illuminate\Database\Concerns; use Closure; +use Illuminate\Database\DeadlockException; use RuntimeException; use Throwable; @@ -87,7 +88,11 @@ protected function handleTransactionException(Throwable $e, $currentAttempt, $ma $this->getName(), $this->transactions ); - throw $e; + throw new DeadlockException( + $e->getMessage(), + $e->getCode(), + $e->getPrevious() + ); } // If there was an exception we will rollback this transaction and then we @@ -226,8 +231,7 @@ protected function handleCommitTransactionException(Throwable $e, $currentAttemp { $this->transactions = max(0, $this->transactions - 1); - if ($this->causedByConcurrencyError($e) && - $currentAttempt < $maxAttempts) { + if ($this->causedByConcurrencyError($e) && $currentAttempt < $maxAttempts) { return; } diff --git a/DeadlockException.php b/DeadlockException.php new file mode 100644 index 000000000..375a39bc9 --- /dev/null +++ b/DeadlockException.php @@ -0,0 +1,10 @@ +