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

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