Skip to content

Commit 2349d88

Browse files
committed
Improve increment exceptions
1 parent 7b2622d commit 2349d88

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Database/Database.php

Lines changed: 5 additions & 4 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;
@@ -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)