mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Combine Duplicate/Limit catches in createField
Same shape as the row-flush combine: multi-type catch with a small ternary for the per-type message. Two pairs collapsed: the single attribute path and the relationship two-way path (which differ only in 'Attribute limit exceeded' vs 'Column limit exceeded').
This commit is contained in:
1 parent
0710fde3a9
commit
3fdcd27925
1 file changed
+8
-28
@@ -691,23 +691,14 @@ class Appwrite extends Destination
|
||||
$this->dbForProject->checkAttribute($table, $column);
|
||||
|
||||
$column = $this->dbForProject->createDocument('attributes', $column);
|
||||
} catch (DuplicateException $e) {
|
||||
$resource->setStatus(Resource::STATUS_ERROR, 'Attribute already exists');
|
||||
} catch (DuplicateException | LimitException $e) {
|
||||
$message = $e instanceof DuplicateException ? 'Attribute already exists' : 'Attribute limit exceeded';
|
||||
$resource->setStatus(Resource::STATUS_ERROR, $message);
|
||||
$this->addError(new Exception(
|
||||
resourceName: $resource->getName(),
|
||||
resourceGroup: $resource->getGroup(),
|
||||
resourceId: $resource->getId(),
|
||||
message: 'Attribute already exists',
|
||||
previous: $e,
|
||||
));
|
||||
return false;
|
||||
} catch (LimitException $e) {
|
||||
$resource->setStatus(Resource::STATUS_ERROR, 'Attribute limit exceeded');
|
||||
$this->addError(new Exception(
|
||||
resourceName: $resource->getName(),
|
||||
resourceGroup: $resource->getGroup(),
|
||||
resourceId: $resource->getId(),
|
||||
message: 'Attribute limit exceeded',
|
||||
message: $message,
|
||||
previous: $e,
|
||||
));
|
||||
return false;
|
||||
@@ -753,27 +744,16 @@ class Appwrite extends Destination
|
||||
]);
|
||||
|
||||
$this->dbForProject->createDocument('attributes', $twoWayAttribute);
|
||||
} catch (DuplicateException $e) {
|
||||
} catch (DuplicateException | LimitException $e) {
|
||||
$this->dbForProject->deleteDocument('attributes', $column->getId());
|
||||
|
||||
$resource->setStatus(Resource::STATUS_ERROR, 'Attribute already exists');
|
||||
$message = $e instanceof DuplicateException ? 'Attribute already exists' : 'Column limit exceeded';
|
||||
$resource->setStatus(Resource::STATUS_ERROR, $message);
|
||||
$this->addError(new Exception(
|
||||
resourceName: $resource->getName(),
|
||||
resourceGroup: $resource->getGroup(),
|
||||
resourceId: $resource->getId(),
|
||||
message: 'Attribute already exists',
|
||||
previous: $e,
|
||||
));
|
||||
return false;
|
||||
} catch (LimitException $e) {
|
||||
$this->dbForProject->deleteDocument('attributes', $column->getId());
|
||||
|
||||
$resource->setStatus(Resource::STATUS_ERROR, 'Column limit exceeded');
|
||||
$this->addError(new Exception(
|
||||
resourceName: $resource->getName(),
|
||||
resourceGroup: $resource->getGroup(),
|
||||
resourceId: $resource->getId(),
|
||||
message: 'Column limit exceeded',
|
||||
message: $message,
|
||||
previous: $e,
|
||||
));
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user