Skip to content

Commit d4b2048

Browse files
authored
Merge pull request #603 from utopia-php/feat-type-except
Improve increment exceptions
2 parents 7b2622d + 09196fb commit d4b2048

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/Database/Database.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Utopia\Database\Exception\Restricted as RestrictedException;
1919
use Utopia\Database\Exception\Structure as StructureException;
2020
use Utopia\Database\Exception\Timeout as TimeoutException;
21+
use Utopia\Database\Exception\Type as TypeException;
2122
use Utopia\Database\Helpers\ID;
2223
use Utopia\Database\Helpers\Permission;
2324
use Utopia\Database\Helpers\Role;
@@ -4975,7 +4976,7 @@ public function createOrUpdateDocumentsWithIncrease(
49754976
->setAttribute('$id', empty($document->getId()) ? ID::unique() : $document->getId())
49764977
->setAttribute('$collection', $collection->getId())
49774978
->setAttribute('$updatedAt', empty($updatedAt) || !$this->preserveDates ? $time : $updatedAt)
4978-
->removeAttribute('$internalId');
4979+
->removeAttribute('$sequence');
49794980

49804981
if ($old->isEmpty()) {
49814982
$createdAt = $document->getCreatedAt();
@@ -5143,11 +5144,11 @@ public function increaseDocumentAttribute(string $collection, string $id, string
51435144
*/
51445145
$attr = \end($attr);
51455146
if (!in_array($attr->getAttribute('type'), $whiteList)) {
5146-
throw new DatabaseException('Attribute type must be one of: ' . implode(',', $whiteList));
5147+
throw new TypeException('Attribute type must be one of: ' . implode(',', $whiteList));
51475148
}
51485149

51495150
if ($max && ($document->getAttribute($attribute) + $value > $max)) {
5150-
throw new DatabaseException('Attribute value exceeds maximum limit: ' . $max);
5151+
throw new LimitException('Attribute value exceeds maximum limit: ' . $max);
51515152
}
51525153

51535154
$time = DateTime::now();
@@ -5234,11 +5235,11 @@ public function decreaseDocumentAttribute(string $collection, string $id, string
52345235
*/
52355236
$attr = \end($attr);
52365237
if (!in_array($attr->getAttribute('type'), $whiteList)) {
5237-
throw new DatabaseException('Attribute type must be one of: ' . implode(',', $whiteList));
5238+
throw new TypeException('Attribute type must be one of: ' . \implode(',', $whiteList));
52385239
}
52395240

52405241
if ($min && ($document->getAttribute($attribute) - $value < $min)) {
5241-
throw new DatabaseException('Attribute value Exceeds minimum limit ' . $min);
5242+
throw new LimitException('Attribute value exceeds minimum limit: ' . $min);
52425243
}
52435244

52445245
$time = DateTime::now();

src/Database/Exception/Type.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Utopia\Database\Exception;
4+
5+
use Utopia\Database\Exception;
6+
7+
class Type extends Exception
8+
{
9+
}

0 commit comments

Comments
 (0)