ExceptionHandler.php in Drupal 10
File
core/modules/mysql/src/Driver/Database/mysql/ExceptionHandler.php
View source
<?php
namespace Drupal\mysql\Driver\Database\mysql;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Database\ExceptionHandler as BaseExceptionHandler;
use Drupal\Core\Database\IntegrityConstraintViolationException;
use Drupal\Core\Database\StatementInterface;
class ExceptionHandler extends BaseExceptionHandler {
public function handleExecutionException(\Exception $exception, StatementInterface $statement, array $arguments = [], array $options = []) : void {
if ($exception instanceof \PDOException) {
$code = is_int($exception
->getCode()) ? $exception
->getCode() : 0;
if (($exception->errorInfo[1] ?? NULL) === 1153) {
$message = Unicode::truncateBytes($exception
->getMessage(), Connection::MIN_MAX_ALLOWED_PACKET);
throw new DatabaseExceptionWrapper($message, $code, $exception);
}
$message = $exception
->getMessage() . ": " . $statement
->getQueryString() . "; " . print_r($arguments, TRUE);
if (substr($exception
->getCode(), -6, -3) == '23' || ($exception->errorInfo[1] ?? NULL) === 1364) {
throw new IntegrityConstraintViolationException($message, $code, $exception);
}
throw new DatabaseExceptionWrapper($message, 0, $exception);
}
throw $exception;
}
}