1
0
Fork 0
mirror of synced 2024-06-29 11:40:45 +12:00

Better error handling

This commit is contained in:
Eldad Fux 2020-03-08 17:38:51 +02:00
parent 0aab05771d
commit 5eedfdd3fe

View file

@ -70,6 +70,10 @@ $utopia->post('/v1/database/collections')
throw new Exception('Failed saving document to DB', 500);
}
if (false === $data) {
throw new Exception('Failed saving collection to DB', 500);
}
$data = $data->getArrayCopy();
$webhook
@ -193,16 +197,24 @@ $utopia->put('/v1/database/collections/:collectionId')
], $rule);
}
$collection = $projectDB->updateDocument(array_merge($collection->getArrayCopy(), [
'name' => $name,
'structure' => true,
'dateUpdated' => time(),
'$permissions' => [
'read' => $read,
'write' => $write,
],
'rules' => $rules,
]));
try {
$collection = $projectDB->updateDocument(array_merge($collection->getArrayCopy(), [
'name' => $name,
'structure' => true,
'dateUpdated' => time(),
'$permissions' => [
'read' => $read,
'write' => $write,
],
'rules' => $parsedRules,
]));
} catch (AuthorizationException $exception) {
throw new Exception('Unauthorized action', 401);
} catch (StructureException $exception) {
throw new Exception('Bad structure. '.$exception->getMessage(), 400);
} catch (\Exception $exception) {
throw new Exception('Failed saving document to DB', 500);
}
if (false === $collection) {
throw new Exception('Failed saving collection to DB', 500);