From 703a528d6d11aed6c46036aa3e4a254a37aaed84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 25 Jul 2022 10:21:24 +0000 Subject: [PATCH] Catch OAuth duplication error --- app/controllers/api/account.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 6c90441afb..2f724419a1 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -540,7 +540,11 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') Authorization::setRole('user:' . $user->getId()); - $dbForProject->updateDocument('users', $user->getId(), $user); + try { + $dbForProject->updateDocument('users', $user->getId(), $user); + } catch (Duplicate $th) { + throw new Exception('Account already exists', 409, Exception::USER_ALREADY_EXISTS); + } $session = $dbForProject->createDocument('sessions', $session ->setAttribute('$read', ['user:' . $user->getId()])