From f5d69b4b0aaaba03480323d798097412179f2811 Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Thu, 9 Sep 2021 13:15:30 -0400 Subject: [PATCH] Catch exceptions in one block --- app/controllers/api/database.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 7cda576626..5560d931d9 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -88,16 +88,13 @@ $attributesCallback = function ($collectionId, $attribute, $response, $dbForInte try { $dbForInternal->checkAttribute($collection, $attribute); - } catch (LimitException $exception) { - throw new Exception('Attribute limit exceeded', 400); - } - - try { $attribute = $dbForInternal->createDocument('attributes', $attribute); - } catch (DuplicateException $th) { + } + catch (DuplicateException $exception) { throw new Exception('Attribute already exists', 409); - } catch (LimitException $e) { - throw new Exception($e->getMessage(), 400); + } + catch (LimitException $exception) { + throw new Exception('Attribute limit exceeded', 400); } $dbForInternal->purgeDocument('collections', $collectionId);