Skip to content

Commit 81a9716

Browse files
authored
Merge pull request #1 from Meldiron/add-exception-class
Improve exceptions
2 parents d0b6f41 + 672a670 commit 81a9716

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

composer.lock

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

src/Database/Adapter/Mongo.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Utopia\Database\Adapter;
44

55
use Exception;
6-
use Utopia\Database\Exception as DatabaseException;
6+
77
use MongoDB\BSON\ObjectId;
88
use MongoDB\BSON\Regex;
99
use MongoDB\BSON\UTCDateTime;
@@ -12,6 +12,7 @@
1212
use Utopia\Database\Document;
1313
use Utopia\Database\Database;
1414
use Utopia\Database\Exception\Duplicate;
15+
use Utopia\Database\Exception as DatabaseException;
1516
use Utopia\Database\Validator\Authorization;
1617
use Utopia\Database\Query;
1718
use Utopia\Mongo\Exception as MongoException;
@@ -605,7 +606,7 @@ public function find(string $collection, array $queries = [], int $limit = 25, i
605606
$attribute = $orderAttributes[0];
606607

607608
if (is_null($cursor[$attribute] ?? null)) {
608-
throw new DatabaseException("Order attribute '{$attribute}' is empty.");
609+
throw new Exception("Order attribute '{$attribute}' is empty.");
609610
}
610611

611612
$orderOperatorInternalId = Query::TYPE_GREATER;

src/Database/Adapter/Mongo/MongoClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private function receive(): \stdClass|array|int
154154
$result = BSON\toPHP(substr($res, 21, $responseLength - 21));
155155

156156
if (property_exists($result, "writeErrors")) {
157-
throw new DuplicateException($result->writeErrors[0]->errmsg);
157+
throw new Exception($result->writeErrors[0]->errmsg);
158158
}
159159

160160
if (property_exists($result, "n") && $result->ok == 1) {

src/Database/Adapter/SQLite.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public function createDocument(string $collection, Document $document): Document
368368
switch ($e->getCode()) {
369369
case "1062":
370370
case "23000":
371-
throw new Duplicate('Duplicated document: ' . $e->getMessage());
371+
throw new Duplicate('Duplicated document');
372372
break;
373373
default:
374374
throw $e;
@@ -555,7 +555,7 @@ public function updateDocument(string $collection, Document $document): Document
555555
switch ($e->getCode()) {
556556
case '1062':
557557
case '23000':
558-
throw new Duplicate('Duplicated document: ' . $e->getMessage());
558+
throw new Duplicate('Duplicated document');
559559

560560
default:
561561
throw $e;

src/Database/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use Throwable;
66
use Exception;
7-
use Utopia\Database\Exception as DatabaseException;
87
use Utopia\Database\Validator\Authorization;
98
use Utopia\Database\Validator\Structure;
9+
use Utopia\Database\Exception as DatabaseException;
1010
use Utopia\Database\Exception\Authorization as AuthorizationException;
1111
use Utopia\Database\Exception\Duplicate as DuplicateException;
1212
use Utopia\Database\Exception\Limit as LimitException;

src/Database/Permission.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Utopia\Database;
44

5-
use Exception;
65
use Utopia\Database\Exception as DatabaseException;
76

87
class Permission

0 commit comments

Comments
 (0)