Handle structure exception

This commit is contained in:
Jake Barnby
2025-09-12 21:47:40 +12:00
parent 38dc92bfa7
commit 7120bce761
5 changed files with 10 additions and 5 deletions
@@ -36,7 +36,7 @@ class Create extends Action
$this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)
->setHttpPath('/v1/databases/transactions/:transactionId/operations')
->desc('Add operations to transaction')
->desc('Create operations scoped to a transaction')
->groups(['api', 'database', 'transactions'])
->label('scope', 'transactions.write')
->label('resourceType', RESOURCE_TYPE_DATABASES)
@@ -17,7 +17,7 @@ use Utopia\Database\Exception\Authorization;
use Utopia\Database\Exception\Conflict as ConflictException;
use Utopia\Database\Exception\Duplicate as DuplicateException;
use Utopia\Database\Exception\NotFound as NotFoundException;
use Utopia\Database\Exception\Structure;
use Utopia\Database\Exception\Structure as StructureException;
use Utopia\Database\Exception\Transaction as TransactionException;
use Utopia\Database\Query;
use Utopia\Database\Validator\UID;
@@ -210,6 +210,11 @@ class Update extends Action
'status' => 'failed',
]));
throw new Exception(Exception::TRANSACTION_CONFLICT, previous: $e);
} catch (StructureException $e) {
$dbForProject->updateDocument('transactions', $transactionId, new Document([
'status' => 'failed',
]));
throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $e->getMessage());
} catch (TransactionException $e) {
$dbForProject->updateDocument('transactions', $transactionId, new Document([
'status' => 'failed',
@@ -30,7 +30,7 @@ class Create extends OperationsCreate
$this
->setHttpMethod(self::HTTP_REQUEST_METHOD_POST)
->setHttpPath('/v1/tablesdb/transactions/:transactionId/operations')
->desc('Add operations to transaction')
->desc('Create operations scoped to a transaction')
->groups(['api', 'database', 'transactions'])
->label('scope', 'transactions.write')
->label('resourceType', RESOURCE_TYPE_DATABASES)
@@ -96,7 +96,7 @@ class TransactionsTest extends Scope
/**
* Test adding operations to a transaction
*/
public function testAddOperations(): void
public function testCreateOperations(): void
{
// Create database first
$database = $this->client->call(Client::METHOD_POST, '/databases', array_merge([
@@ -96,7 +96,7 @@ class TransactionsTest extends Scope
/**
* Test adding operations to a transaction
*/
public function testAddOperations(): void
public function testCreateOperations(): void
{
// Create database first
$database = $this->client->call(Client::METHOD_POST, '/tablesdb', array_merge([