Skip to content

Commit 67d2ab4

Browse files
authored
Merge pull request #554 from ArnabChatterjee20k/feat/adding-order-exceptions
Adding new order exception and using it in find methods
2 parents e589efd + 1e3df24 commit 67d2ab4

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/Database/Adapter/MariaDB.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Utopia\Database\Exception as DatabaseException;
1212
use Utopia\Database\Exception\Duplicate as DuplicateException;
1313
use Utopia\Database\Exception\NotFound as NotFoundException;
14+
use Utopia\Database\Exception\Order as OrderException;
1415
use Utopia\Database\Exception\Timeout as TimeoutException;
1516
use Utopia\Database\Exception\Truncate as TruncateException;
1617
use Utopia\Database\Helpers\ID;
@@ -1716,7 +1717,10 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
17161717
}
17171718

17181719
if (\is_null($cursor[$originalAttribute] ?? null)) {
1719-
throw new DatabaseException("Order attribute '{$originalAttribute}' is empty");
1720+
throw new OrderException(
1721+
message: "Order attribute '{$originalAttribute}' is empty",
1722+
attribute: $originalAttribute
1723+
);
17201724
}
17211725

17221726
$binds[':cursor'] = $cursor[$originalAttribute];

src/Database/Adapter/Postgres.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Utopia\Database\Document;
1111
use Utopia\Database\Exception as DatabaseException;
1212
use Utopia\Database\Exception\Duplicate as DuplicateException;
13+
use Utopia\Database\Exception\Order as OrderException;
1314
use Utopia\Database\Exception\Timeout as TimeoutException;
1415
use Utopia\Database\Exception\Transaction as TransactionException;
1516
use Utopia\Database\Exception\Truncate as TruncateException;
@@ -1549,7 +1550,10 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
15491550
}
15501551

15511552
if (\is_null($cursor[$originalAttribute] ?? null)) {
1552-
throw new DatabaseException("Order attribute '{$originalAttribute}' is empty");
1553+
throw new OrderException(
1554+
message: "Order attribute '{$originalAttribute}' is empty",
1555+
attribute: $originalAttribute
1556+
);
15531557
}
15541558

15551559
$binds[':cursor'] = $cursor[$originalAttribute];

src/Database/Exception/Order.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Utopia\Database\Exception;
4+
5+
use Throwable;
6+
use Utopia\Database\Exception;
7+
8+
class Order extends Exception
9+
{
10+
protected ?string $attribute;
11+
public function __construct(string $message, int|string $code = 0, ?Throwable $previous = null, ?string $attribute = null)
12+
{
13+
$this->attribute = $attribute;
14+
parent::__construct($message, $code, $previous);
15+
}
16+
public function getAttribute(): ?string
17+
{
18+
return $this->attribute;
19+
}
20+
}

0 commit comments

Comments
 (0)