From 758f8e8eb23bdcea2818b13efd3bb14360341b19 Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Wed, 18 Aug 2021 14:49:49 -0400 Subject: [PATCH] Catch duplicate index exception when creating and updating a document --- app/controllers/api/database.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index a6f4853ee9..797e5d15e2 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -1307,6 +1307,9 @@ App::patch('/v1/database/collections/:collectionId/documents/:documentId') catch (AuthorizationException $exception) { throw new Exception('Unauthorized permissions', 401); } + catch (DuplicateException $exception) { + throw new Exception($exception->getMessage(), 400); + } catch (StructureException $exception) { throw new Exception('Bad structure. '.$exception->getMessage(), 400); } @@ -1369,4 +1372,3 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId') ; $response->noContent(); - }); \ No newline at end of file