From 65dbebd103467027f7118dc84cb5896d639f43fd Mon Sep 17 00:00:00 2001 From: Darshan Date: Fri, 9 May 2025 11:09:58 +0530 Subject: [PATCH] misc: fix error types. --- .../Collections/Attributes/Action.php | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php index be6e3d1ff7..d1047e671d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php @@ -150,6 +150,16 @@ abstract class Action extends UtopiaAction : Exception::COLUMN_LIMIT_EXCEEDED; } + /** + * Get the appropriate index invalid exception. + */ + final protected function getInvalidIndexException(): string + { + return $this->isCollectionsAPI() + ? Exception::INDEX_INVALID + : Exception::COLUMN_INDEX_INVALID; + } + /** * Get the correct default unsupported message. */ @@ -480,7 +490,7 @@ abstract class Action extends UtopiaAction $max ??= $attribute->getAttribute('formatOptions')['max']; if ($min > $max) { - throw new Exception($this->getTypeInvalidException(), 'Minimum value must be lesser than maximum value'); + throw new Exception($this->getInvalidValueException(), 'Minimum value must be lesser than maximum value'); } if ($attribute->getAttribute('format') === APP_DATABASE_ATTRIBUTE_INT_RANGE) { @@ -506,17 +516,17 @@ abstract class Action extends UtopiaAction break; case APP_DATABASE_ATTRIBUTE_ENUM: if (empty($elements)) { - throw new Exception($this->getTypeInvalidException(), 'Enum elements must not be empty'); + throw new Exception($this->getInvalidValueException(), 'Enum elements must not be empty'); } foreach ($elements as $element) { if (\strlen($element) === 0) { - throw new Exception($this->getTypeInvalidException(), 'Each enum element must not be empty'); + throw new Exception($this->getInvalidValueException(), 'Each enum element must not be empty'); } } if (!is_null($default) && !in_array($default, $elements)) { - throw new Exception($this->getTypeInvalidException(), 'Default value not found in elements'); + throw new Exception($this->getInvalidValueException(), 'Default value not found in elements'); } $options = [ @@ -575,7 +585,7 @@ abstract class Action extends UtopiaAction } catch (LimitException) { throw new Exception($this->getLimitException()); } catch (IndexException $e) { - throw new Exception(Exception::INDEX_INVALID, $e->getMessage()); + throw new Exception($this->getInvalidIndexException(), $e->getMessage()); } }