Skip to content

Commit 55fe21e

Browse files
fix/feature: problema de silent exceptions, agora todo erro gerará uma exception na aplicação
1 parent 7dfd3eb commit 55fe21e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/Database/Connection.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,4 +475,43 @@ public function getSchemaBuilder()
475475

476476
return $builder;
477477
}
478+
479+
/**
480+
* Run a SQL statement.
481+
*
482+
* @param string $query
483+
* @param array $bindings
484+
* @param \Closure $callback
485+
* @return mixed
486+
*
487+
* @throws \Illuminate\Database\QueryException
488+
*/
489+
protected function runQueryCallback($query, $bindings, Closure $callback)
490+
{
491+
try {
492+
$result = $callback($query, $bindings);
493+
494+
if ($result instanceof \PDOStatement) {
495+
if (isset($errorInfo[0]) && $errorInfo[0] !== '00000') {
496+
$errorInfo = $result->errorInfo();
497+
$finalErrorMessage = sprintf(
498+
'SQLSTATE[%s] [%d] %s',
499+
$errorInfo[0],
500+
(int)$errorInfo[1],
501+
trim(preg_replace(['/^\[\d+\]\s\(severity\s\d+\)\s/', '/\s+/'], ['', ' '], $errorInfo[2]))
502+
);
503+
throw new \PDOException($finalErrorMessage, (int)$errorInfo[1]);
504+
}
505+
}
506+
return $result;
507+
508+
} catch (Throwable $e) {
509+
throw new QueryException(
510+
$this->getName(),
511+
$query,
512+
$this->prepareBindings($bindings),
513+
$e
514+
);
515+
}
516+
}
478517
}

0 commit comments

Comments
 (0)