vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php line 34

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\DBAL\Driver\API\MySQL;
  4. use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
  5. use Doctrine\DBAL\Driver\Exception;
  6. use Doctrine\DBAL\Exception\ConnectionException;
  7. use Doctrine\DBAL\Exception\ConnectionLost;
  8. use Doctrine\DBAL\Exception\DatabaseDoesNotExist;
  9. use Doctrine\DBAL\Exception\DeadlockException;
  10. use Doctrine\DBAL\Exception\DriverException;
  11. use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
  12. use Doctrine\DBAL\Exception\InvalidFieldNameException;
  13. use Doctrine\DBAL\Exception\LockWaitTimeoutException;
  14. use Doctrine\DBAL\Exception\NonUniqueFieldNameException;
  15. use Doctrine\DBAL\Exception\NotNullConstraintViolationException;
  16. use Doctrine\DBAL\Exception\SyntaxErrorException;
  17. use Doctrine\DBAL\Exception\TableExistsException;
  18. use Doctrine\DBAL\Exception\TableNotFoundException;
  19. use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
  20. use Doctrine\DBAL\Query;
  21. /**
  22.  * @internal
  23.  */
  24. final class ExceptionConverter implements ExceptionConverterInterface
  25. {
  26.     /**
  27.      * @link https://dev.mysql.com/doc/mysql-errors/8.0/en/client-error-reference.html
  28.      * @link https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html
  29.      */
  30.     public function convert(Exception $exception, ?Query $query): DriverException
  31.     {
  32.         switch ($exception->getCode()) {
  33.             case 1008:
  34.                 return new DatabaseDoesNotExist($exception$query);
  35.             case 1213:
  36.                 return new DeadlockException($exception$query);
  37.             case 1205:
  38.                 return new LockWaitTimeoutException($exception$query);
  39.             case 1050:
  40.                 return new TableExistsException($exception$query);
  41.             case 1051:
  42.             case 1146:
  43.                 return new TableNotFoundException($exception$query);
  44.             case 1216:
  45.             case 1217:
  46.             case 1451:
  47.             case 1452:
  48.             case 1701:
  49.                 return new ForeignKeyConstraintViolationException($exception$query);
  50.             case 1062:
  51.             case 1557:
  52.             case 1569:
  53.             case 1586:
  54.                 return new UniqueConstraintViolationException($exception$query);
  55.             case 1054:
  56.             case 1166:
  57.             case 1611:
  58.                 return new InvalidFieldNameException($exception$query);
  59.             case 1052:
  60.             case 1060:
  61.             case 1110:
  62.                 return new NonUniqueFieldNameException($exception$query);
  63.             case 1064:
  64.             case 1149:
  65.             case 1287:
  66.             case 1341:
  67.             case 1342:
  68.             case 1343:
  69.             case 1344:
  70.             case 1382:
  71.             case 1479:
  72.             case 1541:
  73.             case 1554:
  74.             case 1626:
  75.                 return new SyntaxErrorException($exception$query);
  76.             case 1044:
  77.             case 1045:
  78.             case 1046:
  79.             case 1049:
  80.             case 1095:
  81.             case 1142:
  82.             case 1143:
  83.             case 1227:
  84.             case 1370:
  85.             case 1429:
  86.             case 2002:
  87.             case 2005:
  88.             case 2054:
  89.                 return new ConnectionException($exception$query);
  90.             case 2006:
  91.                 return new ConnectionLost($exception$query);
  92.             case 1048:
  93.             case 1121:
  94.             case 1138:
  95.             case 1171:
  96.             case 1252:
  97.             case 1263:
  98.             case 1364:
  99.             case 1566:
  100.                 return new NotNullConstraintViolationException($exception$query);
  101.         }
  102.         return new DriverException($exception$query);
  103.     }
  104. }