Better error handling
This commit is contained in:
parent
0aab05771d
commit
5eedfdd3fe
1 changed files with 22 additions and 10 deletions
|
@ -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,6 +197,7 @@ $utopia->put('/v1/database/collections/:collectionId')
|
|||
], $rule);
|
||||
}
|
||||
|
||||
try {
|
||||
$collection = $projectDB->updateDocument(array_merge($collection->getArrayCopy(), [
|
||||
'name' => $name,
|
||||
'structure' => true,
|
||||
|
@ -201,8 +206,15 @@ $utopia->put('/v1/database/collections/:collectionId')
|
|||
'read' => $read,
|
||||
'write' => $write,
|
||||
],
|
||||
'rules' => $rules,
|
||||
'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);
|
||||
|
|
Loading…
Reference in a new issue