From 438a2d7d3ad5ae0992ad6530a84d42f4d4d4a985 Mon Sep 17 00:00:00 2001 From: Iman Ghafoori Date: Mon, 25 Apr 2022 23:31:36 +0430 Subject: [PATCH] throw deadlock exception --- .../Database/Concerns/ManagesTransactions.php | 10 +++++++--- src/Illuminate/Database/DeadlockException.php | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/Illuminate/Database/DeadlockException.php diff --git a/src/Illuminate/Database/Concerns/ManagesTransactions.php b/src/Illuminate/Database/Concerns/ManagesTransactions.php index d8932d4ee092..038e104779f9 100644 --- a/src/Illuminate/Database/Concerns/ManagesTransactions.php +++ b/src/Illuminate/Database/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/src/Illuminate/Database/DeadlockException.php b/src/Illuminate/Database/DeadlockException.php new file mode 100644 index 000000000000..375a39bc9658 --- /dev/null +++ b/src/Illuminate/Database/DeadlockException.php @@ -0,0 +1,10 @@ +