From bc0cc515712c029eeeec8097b706dbe68137bd66 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Fri, 5 Apr 2024 15:20:12 -0700 Subject: [PATCH 1/5] Removed nested try-catch --- lib/Controller/AccountController.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 17d6e4c9..33aa8f57 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -156,11 +156,7 @@ class AccountController extends Controller { $this->session->remove(self::SESSION_USERNAME_CHECK); $this->session->remove(self::CAPTCHA_VERIFIED_CHECK); - try { - $this->userService->addUsernameToCommonDataStore($username); - } catch (Exception $e) { - $this->logger->logException($e, ['app' => Application::APP_ID]); - } + $this->userService->addUsernameToCommonDataStore($username); $response->setStatus(200); $response->setData(['success' => true]); -- GitLab From 56b148aba521f5f2954e6013efaa7b169ac84296 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 8 Apr 2024 11:33:13 -0700 Subject: [PATCH 2/5] exception added --- .../AddUsernameToCommonStoreException.php | 9 +++++++++ lib/Service/UserService.php | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 lib/Exception/AddUsernameToCommonStoreException.php diff --git a/lib/Exception/AddUsernameToCommonStoreException.php b/lib/Exception/AddUsernameToCommonStoreException.php new file mode 100644 index 00000000..c7fa6da0 --- /dev/null +++ b/lib/Exception/AddUsernameToCommonStoreException.php @@ -0,0 +1,9 @@ +apiConfig['commonServicesURL']; $commonApiVersion = $this->apiConfig['commonApiVersion']; @@ -505,7 +516,7 @@ class UserService { $this->curl->post($url, $params, $headers); if ($this->curl->getLastStatusCode() !== 200) { - throw new Exception("Error adding username '$username' to common data store."); + throw new AddUsernameToCommonStoreException("Error adding username '$username' to common data store."); } } } -- GitLab From dc4d6214a6f144284dd002020d6549dbdde69cd2 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 8 Apr 2024 11:35:57 -0700 Subject: [PATCH 3/5] exception added --- lib/Controller/AccountController.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 33aa8f57..001ab1dc 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -23,6 +23,8 @@ use OCP\ISession; use OCP\IURLGenerator; use OCP\IUserSession; use OCP\L10N\IFactory; +use OCA\EcloudAccounts\Exception\AddUsernameToCommonStoreException; +use OCA\EcloudAccounts\Exception\LDAPUserCreationException; class AccountController extends Controller { protected $appName; @@ -164,6 +166,10 @@ class AccountController extends Controller { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setData(['message' => 'A server-side error occurred while processing your request! Please try again later.', 'success' => false]); $response->setStatus(500); + } catch (AddUsernameToCommonStoreException | Error $e) { + $this->logger->logException($e, ['app' => Application::APP_ID]); + $response->setData(['message' => 'A server-side error occurred while processing your request! Please try again later.', 'success' => false]); + $response->setStatus(500); } catch (Exception $e) { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setData(['message' => 'An error occurred while creating your account!', 'success' => false]); -- GitLab From e8cf8bd5e47baee1fbea064b8632473cfb853941 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 8 Apr 2024 14:26:13 -0700 Subject: [PATCH 4/5] exception added --- lib/Controller/AccountController.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 001ab1dc..8d0de814 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -8,6 +8,8 @@ namespace OCA\EcloudAccounts\Controller; use Exception; use OCA\EcloudAccounts\AppInfo\Application; +use OCA\EcloudAccounts\Exception\AddUsernameToCommonStoreException; +use OCA\EcloudAccounts\Exception\LDAPUserCreationException; use OCA\EcloudAccounts\Service\CaptchaService; use OCA\EcloudAccounts\Service\NewsLetterService; use OCA\EcloudAccounts\Service\UserService; @@ -23,8 +25,6 @@ use OCP\ISession; use OCP\IURLGenerator; use OCP\IUserSession; use OCP\L10N\IFactory; -use OCA\EcloudAccounts\Exception\AddUsernameToCommonStoreException; -use OCA\EcloudAccounts\Exception\LDAPUserCreationException; class AccountController extends Controller { protected $appName; @@ -162,11 +162,7 @@ class AccountController extends Controller { $response->setStatus(200); $response->setData(['success' => true]); - } catch (LDAPUserCreationException | Error $e) { - $this->logger->logException($e, ['app' => Application::APP_ID]); - $response->setData(['message' => 'A server-side error occurred while processing your request! Please try again later.', 'success' => false]); - $response->setStatus(500); - } catch (AddUsernameToCommonStoreException | Error $e) { + } catch (LDAPUserCreationException | AddUsernameToCommonStoreException | Error $e) { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setData(['message' => 'A server-side error occurred while processing your request! Please try again later.', 'success' => false]); $response->setStatus(500); -- GitLab From ea54c00c0e706b1dd9f145e5c2ee358f4c497717 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 8 Apr 2024 16:25:54 -0700 Subject: [PATCH 5/5] changed exception --- lib/Controller/AccountController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 8d0de814..3dae3d79 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -162,10 +162,14 @@ class AccountController extends Controller { $response->setStatus(200); $response->setData(['success' => true]); - } catch (LDAPUserCreationException | AddUsernameToCommonStoreException | Error $e) { + } catch (LDAPUserCreationException | Error $e) { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setData(['message' => 'A server-side error occurred while processing your request! Please try again later.', 'success' => false]); $response->setStatus(500); + } catch (AddUsernameToCommonStoreException $e) { + $this->logger->logException($e, ['app' => Application::APP_ID]); + $response->setStatus(200); + $response->setData(['success' => true]); } catch (Exception $e) { $this->logger->logException($e, ['app' => Application::APP_ID]); $response->setData(['message' => 'An error occurred while creating your account!', 'success' => false]); -- GitLab