update: better signature.

This commit is contained in:
Darshan 2025-12-11 15:59:24 +05:30
parent 2e4ac091d1
commit cb9705f0a2
40 changed files with 124 additions and 134 deletions

View file

@ -389,7 +389,8 @@ class Exception extends \Exception
string $message = null,
int|string $code = null,
\Throwable $previous = null,
?string $view = null
?string $view = null,
array $params = []
) {
$this->errors = Config::getParam('errors');
$this->type = $type;
@ -405,30 +406,19 @@ class Exception extends \Exception
}
}
$this->message = $message ?? $this->errors[$type]['description'];
// Format message with params if provided
if (!empty($params) && $message === null) {
$description = $this->errors[$type]['description'] ?? '';
$this->message = !empty($description) ? sprintf($description, ...$params) : '';
} else {
$this->message = $message ?? $this->errors[$type]['description'];
}
$this->publish = $this->errors[$type]['publish'] ?? ($this->code >= 500);
parent::__construct($this->message, $this->code, $previous);
}
/**
* Create an exception with formatted parameters.
*/
public static function withParams(string $type, mixed ...$params): self
{
$errors = Config::getParam('errors');
$description = $errors[$type]['description'] ?? '';
if (!empty($params) && !empty($description)) {
$message = sprintf($description, ...$params);
} else {
$message = $description;
}
return new self($type, $message);
}
/**
* Get the type of the exception.
*

View file

@ -307,19 +307,19 @@ abstract class Action extends UtopiaAction
$options = $attribute->getAttribute('options', []);
if (in_array($type, Database::SPATIAL_TYPES) && !$dbForProject->getAdapter()->getSupportForSpatialAttributes()) {
throw Exception::withParams($this->getSpatialTypeNotSupportedException(), $type);
throw new Exception($this->getSpatialTypeNotSupportedException(), params: [$type]);
}
$db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($db->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
if (!empty($format)) {
@ -382,9 +382,9 @@ abstract class Action extends UtopiaAction
$dbForProject->checkAttribute($collection, $attribute);
$attribute = $dbForProject->createDocument('attributes', $attribute);
} catch (DuplicateException) {
throw Exception::withParams($this->getDuplicateException(), $key);
throw new Exception($this->getDuplicateException(), params: [$key]);
} catch (LimitException) {
throw Exception::withParams($this->getLimitException(), $collectionId);
throw new Exception($this->getLimitException(), params: [$collectionId]);
} catch (StructureException $e) {
throw new Exception($this->getStructureException(), $e->getMessage());
} catch (Throwable $e) {
@ -426,9 +426,9 @@ abstract class Action extends UtopiaAction
$dbForProject->checkAttribute($relatedCollection, $twoWayAttribute);
$dbForProject->createDocument('attributes', $twoWayAttribute);
} catch (DuplicateException) {
throw Exception::withParams($this->getDuplicateException(), $twoWayKey);
throw new Exception($this->getDuplicateException(), params: [$twoWayKey]);
} catch (LimitException) {
throw Exception::withParams($this->getLimitException(), $relatedCollection->getId());
throw new Exception($this->getLimitException(), params: [$relatedCollection->getId()]);
} catch (StructureException) {
throw new Exception($this->getStructureException());
} catch (Throwable $e) {
@ -477,19 +477,19 @@ abstract class Action extends UtopiaAction
$db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($db->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
$attribute = $dbForProject->getDocument('attributes', $db->getSequence() . '_' . $collection->getSequence() . '_' . $key);
if ($attribute->isEmpty()) {
throw Exception::withParams($this->getNotFoundException(), $key);
throw new Exception($this->getNotFoundException(), params: [$key]);
}
if ($attribute->getAttribute('status') !== 'available') {
@ -590,7 +590,7 @@ abstract class Action extends UtopiaAction
} catch (IndexException) {
throw new Exception(Exception::INDEX_INVALID);
} catch (LimitException) {
throw Exception::withParams($this->getLimitException(), $collectionId);
throw new Exception($this->getLimitException(), params: [$collectionId]);
} catch (RelationshipException $e) {
throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage());
} catch (StructureException $e) {
@ -624,11 +624,11 @@ abstract class Action extends UtopiaAction
newKey: $newKey ?? null
);
} catch (DuplicateException) {
throw Exception::withParams($this->getDuplicateException(), $key);
throw new Exception($this->getDuplicateException(), params: [$key]);
} catch (IndexException $e) {
throw new Exception($this->getInvalidIndexException(), $e->getMessage());
} catch (LimitException) {
throw Exception::withParams($this->getLimitException(), $collectionId);
throw new Exception($this->getLimitException(), params: [$collectionId]);
} catch (TruncateException) {
throw new Exception($this->getInvalidResizeException());
}
@ -644,7 +644,7 @@ abstract class Action extends UtopiaAction
try {
$dbForProject->updateDocument('attributes', $originalUid, $attribute);
} catch (DuplicateException) {
throw Exception::withParams($this->getDuplicateException(), $newKey);
throw new Exception($this->getDuplicateException(), params: [$newKey]);
}
/**

View file

@ -74,17 +74,17 @@ class Delete extends Action
{
$db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($db->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
$attribute = $dbForProject->getDocument('attributes', $db->getSequence() . '_' . $collection->getSequence() . '_' . $key);
if ($attribute->isEmpty()) {
throw Exception::withParams($this->getNotFoundException(), $key);
throw new Exception($this->getNotFoundException(), params: [$key]);
}
$validator = new IndexDependencyValidator(
@ -93,7 +93,7 @@ class Delete extends Action
);
if (!$validator->isValid($attribute)) {
throw Exception::withParams($this->getIndexDependencyException(), $key);
throw new Exception($this->getIndexDependencyException(), params: [$key]);
}
if ($attribute->getAttribute('status') === 'available') {
@ -108,12 +108,12 @@ class Delete extends Action
if ($options['twoWay']) {
$relatedCollection = $dbForProject->getDocument('database_' . $db->getSequence(), $options['relatedCollection']);
if ($relatedCollection->isEmpty()) {
throw Exception::withParams($this->getParentNotFoundException(), $options['relatedCollection']);
throw new Exception($this->getParentNotFoundException(), params: [$options['relatedCollection']]);
}
$relatedAttribute = $dbForProject->getDocument('attributes', $db->getSequence() . '_' . $relatedCollection->getSequence() . '_' . $options['twoWayKey']);
if ($relatedAttribute->isEmpty()) {
throw Exception::withParams($this->getNotFoundException(), $options['twoWayKey']);
throw new Exception($this->getNotFoundException(), params: [$options['twoWayKey']]);
}
if ($relatedAttribute->getAttribute('status') === 'available') {

View file

@ -75,17 +75,17 @@ class Get extends Action
{
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
$attribute = $dbForProject->getDocument('attributes', $database->getSequence() . '_' . $collection->getSequence() . '_' . $key);
if ($attribute->isEmpty()) {
throw Exception::withParams($this->getNotFoundException(), $key);
throw new Exception($this->getNotFoundException(), params: [$key]);
}
$type = $attribute->getAttribute('type');

View file

@ -93,19 +93,19 @@ class Create extends Action
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
$collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collection->getSequence());
if ($collection->isEmpty()) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
$relatedCollectionDocument = $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId);
$relatedCollection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $relatedCollectionDocument->getSequence());
if ($relatedCollection->isEmpty()) {
throw Exception::withParams($this->getParentNotFoundException(), $relatedCollectionId);
throw new Exception($this->getParentNotFoundException(), params: [$relatedCollectionId]);
}
$attributes = $collection->getAttribute('attributes', []);
@ -115,14 +115,14 @@ class Create extends Action
}
if (\strtolower($attribute->getId()) === \strtolower($key)) {
throw Exception::withParams($this->getDuplicateException(), $key);
throw new Exception($this->getDuplicateException(), params: [$key]);
}
if (
\strtolower($attribute->getAttribute('options')['twoWayKey']) === \strtolower($twoWayKey) &&
$attribute->getAttribute('options')['relatedCollection'] === $relatedCollection->getId()
) {
throw Exception::withParams($this->getDuplicateException(), $twoWayKey);
throw new Exception($this->getDuplicateException(), params: [$twoWayKey]);
}
if (

View file

@ -71,12 +71,12 @@ class XList extends Action
{
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
try {

View file

@ -93,7 +93,7 @@ class Create extends Action
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collectionId = $collectionId === 'unique()' ? ID::unique() : $collectionId;
@ -113,11 +113,11 @@ class Create extends Action
'search' => \implode(' ', [$collectionId, $name]),
]));
} catch (DuplicateException) {
throw Exception::withParams($this->getDuplicateException(), $collectionId);
throw new Exception($this->getDuplicateException(), params: [$collectionId]);
} catch (LimitException) {
throw Exception::withParams($this->getLimitException(), $databaseId);
throw new Exception($this->getLimitException(), params: [$databaseId]);
} catch (NotFoundException) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collectionKey = 'database_' . $database->getSequence() . '_collection_' . $collection->getSequence();
@ -205,13 +205,13 @@ class Create extends Action
);
} catch (DuplicateException) {
$dbForProject->deleteDocument($databaseKey, $collection->getId());
throw Exception::withParams($this->getDuplicateException(), $collectionId);
throw new Exception($this->getDuplicateException(), params: [$collectionId]);
} catch (IndexException $e) {
$dbForProject->deleteDocument($databaseKey, $collection->getId());
throw new Exception($this->getInvalidIndexException(), $e->getMessage());
} catch (LimitException) {
$dbForProject->deleteDocument($databaseKey, $collection->getId());
throw Exception::withParams($this->getLimitException(), $collectionId);
throw new Exception($this->getLimitException(), params: [$collectionId]);
} catch (\Throwable $e) {
$dbForProject->deleteDocument($databaseKey, $collection->getId());
throw $e;
@ -227,7 +227,7 @@ class Create extends Action
}
} catch (DuplicateException) {
$this->cleanup($dbForProject, $databaseKey, $collectionKey, $collection->getId());
throw Exception::withParams($this->getDuplicateException(), $collectionId);
throw new Exception($this->getDuplicateException(), params: [$collectionId]);
} catch (\Throwable $e) {
$this->cleanup($dbForProject, $databaseKey, $collectionKey, $collection->getId());
throw $e;

View file

@ -71,12 +71,12 @@ class Delete extends Action
{
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw Exception::withParams($this->getNotFoundException(), $collectionId);
throw new Exception($this->getNotFoundException(), params: [$collectionId]);
}
if (!$dbForProject->deleteDocument('database_' . $database->getSequence(), $collectionId)) {

View file

@ -95,12 +95,12 @@ class Decrement extends Action
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId));
if ($collection->isEmpty()) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
// Handle transaction staging

View file

@ -95,12 +95,12 @@ class Increment extends Action
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId));
if ($collection->isEmpty()) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
// Handle transaction staging

View file

@ -88,12 +88,12 @@ class Delete extends Action
{
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
$hasRelationships = \array_filter(

View file

@ -100,12 +100,12 @@ class Update extends Action
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
if ($transactionId === null) {

View file

@ -90,12 +90,12 @@ class Upsert extends Action
{
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
$hasRelationships = \array_filter(
@ -180,7 +180,7 @@ class Upsert extends Action
} catch (ConflictException) {
throw new Exception($this->getConflictException());
} catch (DuplicateException) {
throw Exception::withParams($this->getDuplicateException(), 'multiple');
throw new Exception($this->getDuplicateException(), params: ['multiple']);
} catch (RelationshipException $e) {
throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage());
} catch (StructureException $e) {

View file

@ -187,12 +187,12 @@ class Create extends Action
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId));
if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
$hasRelationships = \array_filter(
@ -372,7 +372,7 @@ class Create extends Action
? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId))
: $dbForProject->getDocument('transactions', $transactionId);
if ($transaction->isEmpty()) {
throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId);
throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]);
}
if ($transaction->getAttribute('status', '') !== 'pending') {
throw new Exception(Exception::TRANSACTION_NOT_READY);
@ -444,9 +444,9 @@ class Create extends Action
)
);
} catch (DuplicateException) {
throw Exception::withParams($this->getDuplicateException(), $documentId);
throw new Exception($this->getDuplicateException(), params: [$documentId]);
} catch (NotFoundException) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
} catch (RelationshipException $e) {
throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage());
} catch (StructureException $e) {

View file

@ -105,13 +105,13 @@ class Delete extends Action
$isPrivilegedUser = User::isPrivileged(Authorization::getRoles());
if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId));
if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
// Read permission should not be required for delete
@ -125,7 +125,7 @@ class Delete extends Action
}
if ($document->isEmpty()) {
throw Exception::withParams($this->getNotFoundException(), $documentId);
throw new Exception($this->getNotFoundException(), params: [$documentId]);
}
// Handle transaction staging
@ -134,7 +134,7 @@ class Delete extends Action
? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId))
: $dbForProject->getDocument('transactions', $transactionId);
if ($transaction->isEmpty()) {
throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId);
throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]);
}
if ($transaction->getAttribute('status', '') !== 'pending') {
throw new Exception(Exception::TRANSACTION_NOT_READY);

View file

@ -80,13 +80,13 @@ class Get extends Action
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId));
if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
try {
@ -114,7 +114,7 @@ class Get extends Action
}
if ($document->isEmpty()) {
throw Exception::withParams($this->getNotFoundException(), $documentId);
throw new Exception($this->getNotFoundException(), params: [$documentId]);
}
$operations = 0;

View file

@ -79,17 +79,17 @@ class XList extends Action
{
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
$document = $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId);
if ($document->isEmpty()) {
throw Exception::withParams($this->getNotFoundException(), $documentId);
throw new Exception($this->getNotFoundException(), params: [$documentId]);
}
try {

View file

@ -104,13 +104,13 @@ class Update extends Action
$isPrivilegedUser = User::isPrivileged(Authorization::getRoles());
if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId));
if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
if ($transactionId === null) {
@ -129,7 +129,7 @@ class Update extends Action
}
if ($document->isEmpty()) {
throw Exception::withParams($this->getNotFoundException(), $documentId);
throw new Exception($this->getNotFoundException(), params: [$documentId]);
}
// Map aggregate permissions into the multiple permissions they represent.
@ -252,7 +252,7 @@ class Update extends Action
? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId))
: $dbForProject->getDocument('transactions', $transactionId);
if ($transaction->isEmpty()) {
throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId);
throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]);
}
if ($transaction->getAttribute('status', '') !== 'pending') {
throw new Exception(Exception::TRANSACTION_NOT_READY);
@ -326,7 +326,7 @@ class Update extends Action
} catch (ConflictException) {
throw new Exception($this->getConflictException());
} catch (DuplicateException) {
throw Exception::withParams($this->getDuplicateException(), $documentId);
throw new Exception($this->getDuplicateException(), params: [$documentId]);
} catch (RelationshipException $e) {
throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage());
} catch (StructureException $e) {

View file

@ -111,12 +111,12 @@ class Upsert extends Action
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId));
if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
if ($transactionId === null) {
@ -262,7 +262,7 @@ class Upsert extends Action
? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId))
: $dbForProject->getDocument('transactions', $transactionId);
if ($transaction->isEmpty()) {
throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId);
throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]);
}
if ($transaction->getAttribute('status', '') !== 'pending') {
throw new Exception(Exception::TRANSACTION_NOT_READY);
@ -335,7 +335,7 @@ class Upsert extends Action
} catch (ConflictException) {
throw new Exception($this->getConflictException());
} catch (DuplicateException) {
throw Exception::withParams($this->getDuplicateException(), $documentId);
throw new Exception($this->getDuplicateException(), params: [$documentId]);
} catch (RelationshipException $e) {
throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $e->getMessage());
} catch (StructureException $e) {

View file

@ -84,12 +84,12 @@ class XList extends Action
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId));
if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw Exception::withParams($this->getParentNotFoundException(), $collectionId);
throw new Exception($this->getParentNotFoundException(), params: [$collectionId]);
}
try {

View file

@ -65,13 +65,13 @@ class Get extends Action
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw Exception::withParams($this->getNotFoundException(), $collectionId);
throw new Exception($this->getNotFoundException(), params: [$collectionId]);
}
$response->dynamic($collection, $this->getResponseModel());

View file

@ -87,14 +87,14 @@ class Create extends Action
$db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($db->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId);
if ($collection->isEmpty()) {
// table or collection.
throw Exception::withParams($this->getGrandParentNotFoundException(), $collectionId);
throw new Exception($this->getGrandParentNotFoundException(), params: [$collectionId]);
}
$count = $dbForProject->count('indexes', [
@ -105,7 +105,7 @@ class Create extends Action
$limit = $dbForProject->getLimitForIndexes();
if ($count >= $limit) {
throw Exception::withParams($this->getLimitException(), $collectionId);
throw new Exception($this->getLimitException(), params: [$collectionId]);
}
$oldAttributes = \array_map(
@ -148,7 +148,7 @@ class Create extends Action
$attributeIndex = \array_search($attribute, array_column($oldAttributes, 'key'));
if ($attributeIndex === false) {
throw Exception::withParams($this->getParentUnknownException(), $attribute);
throw new Exception($this->getParentUnknownException(), params: [$attribute]);
}
$attributeStatus = $oldAttributes[$attributeIndex]['status'];
@ -160,7 +160,7 @@ class Create extends Action
}
if ($attributeStatus !== 'available') {
throw Exception::withParams($this->getParentNotAvailableException(), $oldAttributes[$attributeIndex]['key']);
throw new Exception($this->getParentNotAvailableException(), params: [$oldAttributes[$attributeIndex]['key']]);
}
if (empty($lengths[$i])) {
@ -208,7 +208,7 @@ class Create extends Action
try {
$index = $dbForProject->createDocument('indexes', $index);
} catch (DuplicateException) {
throw Exception::withParams($this->getDuplicateException(), $key);
throw new Exception($this->getDuplicateException(), params: [$key]);
}
$dbForProject->purgeCachedDocument('database_' . $db->getSequence(), $collectionId);

View file

@ -78,19 +78,19 @@ class Delete extends Action
$db = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($db->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $db->getSequence(), $collectionId);
if ($collection->isEmpty()) {
// table or collection.
throw Exception::withParams($this->getGrandParentNotFoundException(), $collectionId);
throw new Exception($this->getGrandParentNotFoundException(), params: [$collectionId]);
}
$index = $dbForProject->getDocument('indexes', $db->getSequence() . '_' . $collection->getSequence() . '_' . $key);
if (empty($index->getId())) {
throw Exception::withParams($this->getNotFoundException(), $key);
throw new Exception($this->getNotFoundException(), params: [$key]);
}
// Only update status if removing available index

View file

@ -67,18 +67,18 @@ class Get extends Action
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
// table or collection.
throw Exception::withParams($this->getGrandParentNotFoundException(), $collectionId);
throw new Exception($this->getGrandParentNotFoundException(), params: [$collectionId]);
}
$index = $collection->find('key', $key, 'indexes');
if (empty($index)) {
throw Exception::withParams($this->getNotFoundException(), $key);
throw new Exception($this->getNotFoundException(), params: [$key]);
}
$response->dynamic($index, $this->getResponseModel());

View file

@ -75,14 +75,14 @@ class XList extends Action
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
// table or collection.
throw Exception::withParams($this->getGrandParentNotFoundException(), $collectionId);
throw new Exception($this->getGrandParentNotFoundException(), params: [$collectionId]);
}
try {

View file

@ -79,14 +79,14 @@ class XList extends Action
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collectionDocument = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
$collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collectionDocument->getSequence());
if ($collection->isEmpty()) {
throw Exception::withParams($this->getNotFoundException(), $collectionId);
throw new Exception($this->getNotFoundException(), params: [$collectionId]);
}
try {

View file

@ -78,12 +78,12 @@ class Update extends Action
{
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$collection = $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId);
if ($collection->isEmpty()) {
throw Exception::withParams($this->getNotFoundException(), $collectionId);
throw new Exception($this->getNotFoundException(), params: [$collectionId]);
}
$permissions ??= $collection->getPermissions();

View file

@ -73,7 +73,7 @@ class Get extends Action
$collection = $dbForProject->getCollection('database_' . $database->getSequence() . '_collection_' . $collectionDocument->getSequence());
if ($collection->isEmpty()) {
throw Exception::withParams($this->getNotFoundException(), $collectionId);
throw new Exception($this->getNotFoundException(), params: [$collectionId]);
}
$periods = Config::getParam('usage', []);

View file

@ -75,7 +75,7 @@ class XList extends Action
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
try {

View file

@ -84,7 +84,7 @@ class Create extends Action
'type' => $this->getDatabaseType(),
]));
} catch (DuplicateException) {
throw Exception::withParams(Exception::DATABASE_ALREADY_EXISTS, $databaseId);
throw new Exception(Exception::DATABASE_ALREADY_EXISTS, params: [$databaseId]);
} catch (StructureException $e) {
throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $e->getMessage());
}
@ -109,13 +109,13 @@ class Create extends Action
try {
$dbForProject->createCollection('database_' . $database->getSequence(), $attributes, $indexes);
} catch (DuplicateException) {
throw Exception::withParams(Exception::DATABASE_ALREADY_EXISTS, $databaseId);
throw new Exception(Exception::DATABASE_ALREADY_EXISTS, params: [$databaseId]);
} catch (IndexException $e) {
throw new Exception(Exception::INDEX_INVALID);
} catch (LimitException) {
// TODO: @Jake, how do we handle this collection/table?
// there's no context awareness at this level on what the api is.
throw Exception::withParams(Exception::COLLECTION_LIMIT_EXCEEDED, $databaseId);
throw new Exception(Exception::COLLECTION_LIMIT_EXCEEDED, params: [$databaseId]);
}
$queueForEvents->setParam('databaseId', $database->getId());

View file

@ -69,7 +69,7 @@ class Delete extends Action
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
if (!$dbForProject->deleteDocument('databases', $databaseId)) {

View file

@ -61,7 +61,7 @@ class Get extends Action
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$response->dynamic($database, UtopiaResponse::MODEL_DATABASE);

View file

@ -75,7 +75,7 @@ class XList extends Action
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
try {

View file

@ -60,7 +60,7 @@ class Delete extends Action
$transaction = $dbForProject->getDocument('transactions', $transactionId);
if ($transaction->isEmpty()) {
throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId);
throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]);
}
$dbForProject->deleteDocument('transactions', $transactionId);

View file

@ -58,7 +58,7 @@ class Get extends Action
$transaction = $dbForProject->getDocument('transactions', $transactionId);
if ($transaction->isEmpty()) {
throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId);
throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]);
}
$response

View file

@ -80,7 +80,7 @@ class Create extends Action
? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId))
: $dbForProject->getDocument('transactions', $transactionId);
if ($transaction->isEmpty()) {
throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId);
throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]);
}
if ($transaction->getAttribute('status', '') !== 'pending') {
throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Invalid or nonpending transaction');
@ -115,14 +115,14 @@ class Create extends Action
$database = $databases[$operation['databaseId']] ??= Authorization::skip(fn () => $dbForProject->getDocument('databases', $operation['databaseId']));
if ($database->isEmpty() || (!$database->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $operation['databaseId']);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$operation['databaseId']]);
}
$collection = $collections[$operation[$this->getGroupId()]] ??=
Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $operation[$this->getGroupId()]));
if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) {
throw Exception::withParams(Exception::COLLECTION_NOT_FOUND, $operation[$this->getGroupId()]);
throw new Exception(Exception::COLLECTION_NOT_FOUND, params: [$operation[$this->getGroupId()]]);
}
if (\in_array($operation['action'], ['bulkCreate', 'bulkUpdate', 'bulkUpsert', 'bulkDelete'])) {
@ -148,7 +148,7 @@ class Create extends Action
$document = $transactionState->getDocument($collectionKey, $documentId, $transactionId);
if ($document->isEmpty() && !$isDependant && $operation['action'] !== 'upsert') {
throw Exception::withParams(Exception::DOCUMENT_NOT_FOUND, $documentId);
throw new Exception(Exception::DOCUMENT_NOT_FOUND, params: [$documentId]);
}
}

View file

@ -118,7 +118,7 @@ class Update extends Action
? Authorization::skip(fn () => $dbForProject->getDocument('transactions', $transactionId))
: $dbForProject->getDocument('transactions', $transactionId);
if ($transaction->isEmpty()) {
throw Exception::withParams(Exception::TRANSACTION_NOT_FOUND, $transactionId);
throw new Exception(Exception::TRANSACTION_NOT_FOUND, params: [$transactionId]);
}
if ($transaction->getAttribute('status', '') !== 'pending') {
throw new Exception(Exception::TRANSACTION_NOT_READY);
@ -247,7 +247,7 @@ class Update extends Action
'status' => 'failed',
])));
throw Exception::withParams(Exception::DOCUMENT_NOT_FOUND, $currentDocumentId ?? 'unknown', previous: $e);
throw new Exception(Exception::DOCUMENT_NOT_FOUND, previous: $e, params: [$currentDocumentId ?? 'unknown']);
} catch (DuplicateException | ConflictException $e) {
Authorization::skip(fn () => $dbForProject->updateDocument('transactions', $transactionId, new Document([
'status' => 'failed',

View file

@ -70,7 +70,7 @@ class Update extends Action
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$database = $dbForProject->updateDocument('databases', $databaseId, $database

View file

@ -67,7 +67,7 @@ class Get extends Action
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
$periods = Config::getParam('usage', []);

View file

@ -70,7 +70,7 @@ class XList extends Action
$database = $dbForProject->getDocument('databases', $databaseId);
if ($database->isEmpty()) {
throw Exception::withParams(Exception::DATABASE_NOT_FOUND, $databaseId);
throw new Exception(Exception::DATABASE_NOT_FOUND, params: [$databaseId]);
}
try {