Update ShowServicios.php
This commit is contained in:
@@ -27,6 +27,7 @@ use Illuminate\Support\Facades\Notification;
|
|||||||
use Twilio\Rest\Client;
|
use Twilio\Rest\Client;
|
||||||
use AshAllenDesign\ShortURL\Facades\ShortURL;
|
use AshAllenDesign\ShortURL\Facades\ShortURL;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
|
|
||||||
class ShowServicios extends Component
|
class ShowServicios extends Component
|
||||||
{
|
{
|
||||||
@@ -550,20 +551,38 @@ class ShowServicios extends Component
|
|||||||
|
|
||||||
$this->tarjetaPlan = false;
|
$this->tarjetaPlan = false;
|
||||||
$this->cantidad_tarjetaPlan = 1;
|
$this->cantidad_tarjetaPlan = 1;
|
||||||
} catch (Exception $e) {
|
|
||||||
// Hacer rollback de cualquier cambio realizado en la base de datos
|
// si todo salió bien → salir del bucle
|
||||||
|
break;
|
||||||
|
} catch (QueryException $e) {
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
|
|
||||||
if ($intento >= $maxIntentos) {
|
// PostgreSQL/MariaDB lanza 23505 cuando hay conflicto de índice único
|
||||||
$this->credenciales = false;
|
if ($e->getCode() == '23505') {
|
||||||
$this->cuentas = [];
|
// ⚡ Reintentar, otra transacción tomó la misma cuenta
|
||||||
|
if ($intento >= $maxIntentos) {
|
||||||
|
$this->alert('warning', 'Error: Otra persona tomó la cuenta al mismo tiempo. Intenta nuevamente.', [
|
||||||
|
'position' => 'top'
|
||||||
|
]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$this->alert('warning', 'Error al comprar: Esta cuenta ha sido tomada por otro usuario al mismo tiempo, intenta nuevamente. Error: ' . $e->getMessage(), [
|
usleep(200000); // 200ms antes de reintentar
|
||||||
'position' => 'top'
|
continue;
|
||||||
]);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
usleep(200000); // 200ms
|
|
||||||
|
// Otros errores no son de concurrencia
|
||||||
|
$this->alert('error', 'Error inesperado en la compra: ' . $e->getMessage(), [
|
||||||
|
'position' => 'top'
|
||||||
|
]);
|
||||||
|
return;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
|
||||||
|
$this->alert('error', 'Error inesperado: ' . $e->getMessage(), [
|
||||||
|
'position' => 'top'
|
||||||
|
]);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user