Skip to content

Commit 2f82c7a

Browse files
authored
Merge pull request #499 from utopia-php/fix-exception-messages
Override messages for processed exceptions
2 parents eb9cb6e + 623108c commit 2f82c7a

File tree

8 files changed

+80
-80
lines changed

8 files changed

+80
-80
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
"coverage": "./vendor/bin/coverage-check ./tmp/clover.xml 90"
3434
},
3535
"require": {
36+
"php": ">=8.3",
3637
"ext-pdo": "*",
3738
"ext-mbstring": "*",
38-
"php": ">=8.3",
3939
"utopia-php/framework": "0.33.*",
4040
"utopia-php/cache": "0.11.*",
4141
"utopia-php/mongo": "0.3.*"
@@ -58,8 +58,8 @@
5858
},
5959
"config": {
6060
"allow-plugins": {
61-
"php-http/discovery": false,
62-
"tbachert/spi": false
61+
"php-http/discovery": true,
62+
"tbachert/spi": true
6363
}
6464
}
6565
}

composer.lock

Lines changed: 54 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Database/Adapter/MariaDB.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,8 +1654,8 @@ public function deleteDocument(string $collection, string $id): bool
16541654
$name = $this->filter($collection);
16551655

16561656
$sql = "
1657-
DELETE FROM {$this->getSQLTable($name)}
1658-
WHERE _uid = :_uid
1657+
DELETE FROM {$this->getSQLTable($name)}
1658+
WHERE _uid = :_uid
16591659
";
16601660

16611661
if ($this->sharedTables) {
@@ -2394,27 +2394,27 @@ protected function processException(PDOException $e): \Exception
23942394
{
23952395
// Timeout
23962396
if ($e->getCode() === '70100' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 1969) {
2397-
return new TimeoutException($e->getMessage(), $e->getCode(), $e);
2397+
return new TimeoutException('Query timed out', $e->getCode(), $e);
23982398
}
23992399

24002400
// Duplicate table
24012401
if ($e->getCode() === '42S01' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 1050) {
2402-
return new DuplicateException($e->getMessage(), $e->getCode(), $e);
2402+
return new DuplicateException('Collection already exists', $e->getCode(), $e);
24032403
}
24042404

24052405
// Duplicate column
24062406
if ($e->getCode() === '42S21' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 1060) {
2407-
return new DuplicateException($e->getMessage(), $e->getCode(), $e);
2407+
return new DuplicateException('Attribute already exists', $e->getCode(), $e);
24082408
}
24092409

24102410
// Duplicate index
24112411
if ($e->getCode() === '42000' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 1061) {
2412-
return new DuplicateException($e->getMessage(), $e->getCode(), $e);
2412+
return new DuplicateException('Index already exists', $e->getCode(), $e);
24132413
}
24142414

24152415
// Duplicate row
24162416
if ($e->getCode() === '23000' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 1062) {
2417-
return new DuplicateException($e->getMessage(), $e->getCode(), $e);
2417+
return new DuplicateException('Document already exists', $e->getCode(), $e);
24182418
}
24192419

24202420
// Data is too big for column resize
@@ -2425,7 +2425,7 @@ protected function processException(PDOException $e): \Exception
24252425

24262426
// Unknown database
24272427
if ($e->getCode() === '42000' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 1049) {
2428-
return new NotFoundException($e->getMessage(), $e->getCode(), $e);
2428+
return new NotFoundException('Database not found', $e->getCode(), $e);
24292429
}
24302430

24312431
return $e;

src/Database/Adapter/Mongo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ public function getKeywords(): array
19341934
protected function processException(Exception $e): \Exception
19351935
{
19361936
if ($e->getCode() === 50) {
1937-
return new Timeout($e->getMessage());
1937+
return new Timeout('Query timed out', $e->getCode(), $e);
19381938
}
19391939

19401940
return $e;

src/Database/Adapter/MySQL.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ protected function processException(PDOException $e): \Exception
8484
{
8585
// Timeout
8686
if ($e->getCode() === 'HY000' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 3024) {
87-
return new TimeoutException($e->getMessage(), $e->getCode(), $e);
87+
return new TimeoutException('Query timed out', $e->getCode(), $e);
8888
}
8989

9090
// Functional index dependency
9191
if ($e->getCode() === 'HY000' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 3837) {
92-
return new DependencyException($e->errorInfo[2], $e->getCode(), $e);
92+
return new DependencyException('Attribute cannot be deleted because it is used in an index', $e->getCode(), $e);
9393
}
9494

9595
return parent::processException($e);

0 commit comments

Comments
 (0)