From db3dafda0897ee3dd3a88cf6b4bc1d34dd693c20 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 1 Apr 2024 15:29:53 -0700 Subject: [PATCH 01/13] better error handling --- lib/Service/UserService.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 5b3d2055..69e2319a 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -310,6 +310,10 @@ class UserService { if (!$ret) { throw new LDAPUserCreationException("Error while adding entry to LDAP for username: " . $username . ' Error: ' . ldap_error($connection), ldap_errno($connection)); } + $user = $this->getUser($username); + if (is_null($user)) { + throw new Exception("Error while creating user: " . $username); + } return $newUserEntry; } /** -- GitLab From fe5ca134f8bf9d0c95ed83962b481f9d28d36780 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 1 Apr 2024 15:32:49 -0700 Subject: [PATCH 02/13] better error handling --- lib/Service/UserService.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 69e2319a..9df01fcf 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -252,8 +252,12 @@ class UserService { if (!empty($recoveryEmail)) { $this->validateRecoveryEmail($recoveryEmail); } - return $this->addNewUserToLDAP($displayname, $recoveryEmail, $username, $userEmail, $password); - + $newUserDetail = $this->addNewUserToLDAP($displayname, $recoveryEmail, $username, $userEmail, $password); + $user = $this->getUser($username); + if (is_null($user)) { + throw new Exception("User " . $username. " not found."); + } + return $newUserDetail; } /** * Validates the recovery email address. @@ -310,10 +314,6 @@ class UserService { if (!$ret) { throw new LDAPUserCreationException("Error while adding entry to LDAP for username: " . $username . ' Error: ' . ldap_error($connection), ldap_errno($connection)); } - $user = $this->getUser($username); - if (is_null($user)) { - throw new Exception("Error while creating user: " . $username); - } return $newUserEntry; } /** -- GitLab From f1805f3f0437a9c479a6fd206c80bab26515d30f Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 1 Apr 2024 19:47:41 -0700 Subject: [PATCH 03/13] removed from setAccountDataLocally --- lib/Service/UserService.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 9df01fcf..38ade75b 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -443,11 +443,6 @@ class UserService { */ public function setAccountDataLocally(string $uid, string $mailAddress, string $quota): void { $user = $this->getUser($uid); - if (is_null($user)) { - $this->logger->error('User not found'); - return; - } - // Set the email address for the user $user->setEMailAddress($mailAddress); -- GitLab From 5c077c2cd09996ce33e0f73e052ee18c7640b901 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 2 Apr 2024 13:10:08 -0700 Subject: [PATCH 04/13] added logs --- lib/Service/UserService.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 38ade75b..fb39393c 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -126,6 +126,7 @@ class UserService { $this->config->setUserValue($uid, 'hide-my-email', 'email-aliases', $aliases); return true; } catch (UnexpectedValueException $e) { + $this->logger->error("Error adding HME alias '$alias' to config for user with UID: $uid. Error: " . $e->getMessage()); return false; } } @@ -252,12 +253,7 @@ class UserService { if (!empty($recoveryEmail)) { $this->validateRecoveryEmail($recoveryEmail); } - $newUserDetail = $this->addNewUserToLDAP($displayname, $recoveryEmail, $username, $userEmail, $password); - $user = $this->getUser($username); - if (is_null($user)) { - throw new Exception("User " . $username. " not found."); - } - return $newUserDetail; + return $this->addNewUserToLDAP($displayname, $recoveryEmail, $username, $userEmail, $password); } /** * Validates the recovery email address. @@ -289,7 +285,7 @@ class UserService { * @return array Information about the added user. * @throws LDAPUserCreationException If there is an error adding new entry to LDAP store */ - private function addNewUserToLDAP(string $displayname, string $recoveryEmail, string $username, string $userEmail, string $password): ?array { + private function addNewUserToLDAP(string $displayName, string $recoveryEmail, string $username, string $userEmail, string $password): ?array { $connection = $this->LDAPConnectionService->getLDAPConnection(); $base = $this->LDAPConnectionService->getLDAPBaseUsers()[0]; @@ -300,7 +296,7 @@ class UserService { 'username' => $username, 'usernameWithoutDomain' => $username, 'userPassword' => $password, - 'displayName' => $displayname, + 'displayName' => $displayName, 'quota' => $quota, 'recoveryMailAddress' => $recoveryEmail, 'active' => 'TRUE', @@ -398,8 +394,10 @@ class UserService { if($hmeAlias != '') { $hmeAliasAdded = $this->addHMEAliasInConfig($username, $hmeAlias); if (!$hmeAliasAdded) { - $this->logger->error('Error adding HME Alias in config.'); + $this->logger->error("Failed to add HME Alias '$hmeAlias' for username '$username' in config."); } + }else { + $this->logger->error("Failed to create HME Alias for username '$username'. Response: " . json_encode($result)); } } /** @@ -430,6 +428,9 @@ class UserService { $result = $this->curl->post($url, $data, $headers); $result = json_decode($result, true); + if ($this->curl->getLastStatusCode() !== 200) { + $this->logger->error("Failed to create new domain alias '$username' for email '$userEmail'."); + } return $result; } /** @@ -443,6 +444,9 @@ class UserService { */ public function setAccountDataLocally(string $uid, string $mailAddress, string $quota): void { $user = $this->getUser($uid); + if (is_null($user)) { + throw new Exception("User with username '$uid' not found."); + } // Set the email address for the user $user->setEMailAddress($mailAddress); @@ -477,7 +481,7 @@ class UserService { return true; } - throw new Exception("Error checking if username is taken at common source, status code: " . (string) $statusCode); + throw new Exception("Error checking if username '$username' is taken at common source, status code: " . (string) $statusCode); } public function addUsernameToCommonDataStore(string $username) : void { @@ -502,7 +506,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 Exception("Error adding username '$username' to common data store."); } } } -- GitLab From 68e5c600a573166e98d286a8571c42f4cfb2ed17 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 2 Apr 2024 13:11:07 -0700 Subject: [PATCH 05/13] php fixer --- lib/Service/UserService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index fb39393c..4da4c0bb 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -126,7 +126,7 @@ class UserService { $this->config->setUserValue($uid, 'hide-my-email', 'email-aliases', $aliases); return true; } catch (UnexpectedValueException $e) { - $this->logger->error("Error adding HME alias '$alias' to config for user with UID: $uid. Error: " . $e->getMessage()); + $this->logger->error("Error adding HME alias '$alias' to config for user with UID: $uid. Error: " . $e->getMessage()); return false; } } @@ -396,7 +396,7 @@ class UserService { if (!$hmeAliasAdded) { $this->logger->error("Failed to add HME Alias '$hmeAlias' for username '$username' in config."); } - }else { + } else { $this->logger->error("Failed to create HME Alias for username '$username'. Response: " . json_encode($result)); } } -- GitLab From c325d7b73577a18865d4f7b09fd09a74ecd685f1 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 2 Apr 2024 14:23:21 -0700 Subject: [PATCH 06/13] php fixer --- lib/Service/UserService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 4da4c0bb..224e3a46 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -248,7 +248,7 @@ class UserService { public function registerUser(string $displayname, string $recoveryEmail, string $username, string $userEmail, string $password): array { if ($this->userExists($username)) { - throw new Exception("Username is already taken."); + throw new Exception("Username '$username' is already taken."); } if (!empty($recoveryEmail)) { $this->validateRecoveryEmail($recoveryEmail); -- GitLab From d12642b94e177c0cb8feefe0665acf5c43863f6f Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 3 Apr 2024 00:44:49 -0700 Subject: [PATCH 07/13] added error --- l10n/de.js | 3 ++- l10n/de.json | 3 ++- l10n/en.js | 3 ++- l10n/en.json | 3 ++- l10n/es.js | 3 ++- l10n/es.json | 3 ++- l10n/fr.js | 3 ++- l10n/fr.json | 3 ++- l10n/it.js | 3 ++- l10n/it.json | 3 ++- lib/Controller/AccountController.php | 2 +- 11 files changed, 21 insertions(+), 11 deletions(-) diff --git a/l10n/de.js b/l10n/de.js index 85981868..1bfab173 100644 --- a/l10n/de.js +++ b/l10n/de.js @@ -83,6 +83,7 @@ OC.L10N.register( "Recovery email address is already taken.": "Die E-Mail-Adresse für die Wiederherstellung ist bereits vergeben.", "You cannot set an email address with a Murena domain as recovery email address.": "Sie können keine E-Mail-Adresse mit einer Murena-Domäne als Wiederherstellungs-E-Mail-Adresse festlegen.", "Captcha is not verified!": "Captcha wird nicht überprüft!", - "A server-side error occurred while processing your request! Please try again later.": "Ein serverseitiger Fehler ist bei der Bearbeitung Ihrer Anfrage aufgetreten! Bitte versuchen Sie es später noch einmal." + "A server-side error occurred while processing your request! Please try again later.": "Ein serverseitiger Fehler ist bei der Bearbeitung Ihrer Anfrage aufgetreten! Bitte versuchen Sie es später noch einmal.", + "An error occurred while creating your account!": "Beim Anlegen Ihres Kontos ist ein Fehler aufgetreten!" }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/de.json b/l10n/de.json index 93a91342..2c366a49 100644 --- a/l10n/de.json +++ b/l10n/de.json @@ -81,7 +81,8 @@ "Recovery email address is already taken.": "Die E-Mail-Adresse für die Wiederherstellung ist bereits vergeben.", "You cannot set an email address with a Murena domain as recovery email address.": "Sie können keine E-Mail-Adresse mit einer Murena-Domäne als Wiederherstellungs-E-Mail-Adresse festlegen.", "Captcha is not verified!": "Captcha wird nicht überprüft!", - "A server-side error occurred while processing your request! Please try again later.": "Ein serverseitiger Fehler ist bei der Bearbeitung Ihrer Anfrage aufgetreten! Bitte versuchen Sie es später noch einmal." + "A server-side error occurred while processing your request! Please try again later.": "Ein serverseitiger Fehler ist bei der Bearbeitung Ihrer Anfrage aufgetreten! Bitte versuchen Sie es später noch einmal.", + "An error occurred while creating your account!": "Beim Anlegen Ihres Kontos ist ein Fehler aufgetreten!" }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/en.js b/l10n/en.js index 70409d73..6f8b1160 100644 --- a/l10n/en.js +++ b/l10n/en.js @@ -87,6 +87,7 @@ OC.L10N.register( "Recovery email address is already taken.": "Recovery email address is already taken.", "You cannot set an email address with a Murena domain as recovery email address.": "You cannot set an email address with a Murena domain as recovery email address.", "Captcha is not verified!": "Captcha is not verified!", - "A server-side error occurred while processing your request! Please try again later.": "A server-side error occurred while processing your request! Please try again later." + "A server-side error occurred while processing your request! Please try again later.": "A server-side error occurred while processing your request! Please try again later.", + "An error occurred while creating your account!": "An error occurred while creating your account!" }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/en.json b/l10n/en.json index cb446611..218c5274 100644 --- a/l10n/en.json +++ b/l10n/en.json @@ -83,7 +83,8 @@ "Recovery email address is already taken.": "Recovery email address is already taken.", "You cannot set an email address with a Murena domain as recovery email address.": "You cannot set an email address with a Murena domain as recovery email address.", "Captcha is not verified!": "Captcha is not verified!", - "A server-side error occurred while processing your request! Please try again later.": "A server-side error occurred while processing your request! Please try again later." + "A server-side error occurred while processing your request! Please try again later.": "A server-side error occurred while processing your request! Please try again later.", + "An error occurred while creating your account!": "An error occurred while creating your account!" }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/es.js b/l10n/es.js index 619717cb..95703173 100644 --- a/l10n/es.js +++ b/l10n/es.js @@ -85,6 +85,7 @@ OC.L10N.register( "Recovery email address is already taken.": "La dirección de correo electrónico de recuperación ya está ocupada.", "You cannot set an email address with a Murena domain as recovery email address.": "No puede establecer una dirección de correo electrónico con un dominio de Murena como dirección de correo electrónico de recuperación.", "Captcha is not verified!": "¡Captcha no está verificado!", - "A server-side error occurred while processing your request! Please try again later.": "Hubo un error en el servidor al procesar tu solicitud. Por favor, inténtalo más tarde." + "A server-side error occurred while processing your request! Please try again later.": "Hubo un error en el servidor al procesar tu solicitud. Por favor, inténtalo más tarde.", + "An error occurred while creating your account!": "¡Hubo un error creando tu cuenta!" }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/es.json b/l10n/es.json index 13871c86..399c0553 100644 --- a/l10n/es.json +++ b/l10n/es.json @@ -84,7 +84,8 @@ "Recovery email address is already taken.": "La dirección de correo electrónico de recuperación ya está ocupada.", "You cannot set an email address with a Murena domain as recovery email address.": "No puede establecer una dirección de correo electrónico con un dominio de Murena como dirección de correo electrónico de recuperación.", "Captcha is not verified!": "¡Captcha no está verificado!", - "A server-side error occurred while processing your request! Please try again later.": "Hubo un error en el servidor al procesar tu solicitud. Por favor, inténtalo más tarde." + "A server-side error occurred while processing your request! Please try again later.": "Hubo un error en el servidor al procesar tu solicitud. Por favor, inténtalo más tarde.", + "An error occurred while creating your account!": "¡Hubo un error creando tu cuenta!" }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/fr.js b/l10n/fr.js index 2c4914e0..2f4e72f9 100644 --- a/l10n/fr.js +++ b/l10n/fr.js @@ -84,6 +84,7 @@ OC.L10N.register( "Recovery email address is already taken.": "L'adresse électronique de récupération est déjà prise.", "You cannot set an email address with a Murena domain as recovery email address.": "Vous ne pouvez pas définir une adresse électronique avec un domaine Murena comme adresse électronique de récupération.", "Captcha is not verified!": "Captcha n'est pas vérifié !", - "A server-side error occurred while processing your request! Please try again later.": "Erreur du serveur dans la gestion de votre demande ! Merci d'essayer ultérieurement." + "A server-side error occurred while processing your request! Please try again later.": "Erreur du serveur dans la gestion de votre demande ! Merci d'essayer ultérieurement.", + "An error occurred while creating your account!": "Une erreur s'est produite lors de la création de votre compte!" }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/fr.json b/l10n/fr.json index 60e11c06..6f7697ec 100644 --- a/l10n/fr.json +++ b/l10n/fr.json @@ -83,7 +83,8 @@ "Recovery email address is already taken.": "L'adresse électronique de récupération est déjà prise.", "You cannot set an email address with a Murena domain as recovery email address.": "Vous ne pouvez pas définir une adresse électronique avec un domaine Murena comme adresse électronique de récupération.", "Captcha is not verified!": "Captcha n'est pas vérifié !", - "A server-side error occurred while processing your request! Please try again later.": "Erreur du serveur dans la gestion de votre demande ! Merci d'essayer ultérieurement." + "A server-side error occurred while processing your request! Please try again later.": "Erreur du serveur dans la gestion de votre demande ! Merci d'essayer ultérieurement.", + "An error occurred while creating your account!": "Une erreur s'est produite lors de la création de votre compte!" }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/l10n/it.js b/l10n/it.js index 7a246e1e..b65ec705 100644 --- a/l10n/it.js +++ b/l10n/it.js @@ -84,6 +84,7 @@ OC.L10N.register( "Recovery email address is already taken.": "L'indirizzo e-mail di recupero è già stato preso.", "You cannot set an email address with a Murena domain as recovery email address.": "Non è possibile impostare un indirizzo e-mail con un dominio Murena come indirizzo e-mail di recupero.", "Captcha is not verified!": "Il Captcha non è verificato!", - "A server-side error occurred while processing your request! Please try again later.": "Si è verificato un errore lato server nel processare la tua richiesta! Ritenta più tardi." + "A server-side error occurred while processing your request! Please try again later.": "Si è verificato un errore lato server nel processare la tua richiesta! Ritenta più tardi.", + "An error occurred while creating your account!": "Si è verificato un errore nella creazione dell'account!" }, "nplurals=2; plural=(n != 1);"); diff --git a/l10n/it.json b/l10n/it.json index a62613bd..0f03e188 100644 --- a/l10n/it.json +++ b/l10n/it.json @@ -79,7 +79,8 @@ "Recovery email address is already taken.": "L'indirizzo e-mail di recupero è già stato preso.", "You cannot set an email address with a Murena domain as recovery email address.": "Non è possibile impostare un indirizzo e-mail con un dominio Murena come indirizzo e-mail di recupero.", "Captcha is not verified!": "Il Captcha non è verificato!", - "A server-side error occurred while processing your request! Please try again later.": "Si è verificato un errore lato server nel processare la tua richiesta! Ritenta più tardi." + "A server-side error occurred while processing your request! Please try again later.": "Si è verificato un errore lato server nel processare la tua richiesta! Ritenta più tardi.", + "An error occurred while creating your account!": "Si è verificato un errore nella creazione dell'account!" }, "pluralForm": "nplurals=2; plural=(n != 1);" } diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 18a1613a..412bda44 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -169,7 +169,7 @@ class AccountController extends Controller { $response->setData(['message' => 'A server-side error occurred while processing your request! Please try again later.', 'success' => false]); $response->setStatus(500); } catch (Exception $e) { - $response->setData(['message' => $e->getMessage(), 'success' => false]); + $response->setData(['message' => 'An error occurred while creating your account!', 'success' => false]); $response->setStatus(500); } -- GitLab From d45efa8925f282946ea3e2188dcca3d211bbb366 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 3 Apr 2024 00:46:17 -0700 Subject: [PATCH 08/13] added error --- lib/Service/UserService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 224e3a46..3c83379f 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -445,6 +445,7 @@ class UserService { public function setAccountDataLocally(string $uid, string $mailAddress, string $quota): void { $user = $this->getUser($uid); if (is_null($user)) { + $this->logger->error("User with username '$uid' not found."); throw new Exception("User with username '$uid' not found."); } // Set the email address for the user -- GitLab From c629cbb0dfea50942665959f607e82032b724206 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 3 Apr 2024 00:49:58 -0700 Subject: [PATCH 09/13] added error --- lib/Service/UserService.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 3c83379f..6a092113 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -162,6 +162,7 @@ class UserService { $this->curl->delete($url, $params, $headers); if ($this->curl->getLastStatusCode() !== 200) { + $this->logger->error('Error deleting mail folder of' . $email . '. Status Code: '.$this->curl->getLastStatusCode()); throw new Exception('Error deleting mail folder of' . $email . '. Status Code: '.$this->curl->getLastStatusCode()); } } @@ -481,7 +482,7 @@ class UserService { if ($statusCode === 200) { return true; } - + $this->logger->error("Error checking if username '$username' is taken at common source, status code: " . (string) $statusCode); throw new Exception("Error checking if username '$username' is taken at common source, status code: " . (string) $statusCode); } @@ -507,6 +508,7 @@ class UserService { $this->curl->post($url, $params, $headers); if ($this->curl->getLastStatusCode() !== 200) { + $this->logger->error("Error adding username '$username' to common data store."); throw new Exception("Error adding username '$username' to common data store."); } } -- GitLab From 8550953695668d2888b3d3afac754a79515d7ac5 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 3 Apr 2024 00:51:43 -0700 Subject: [PATCH 10/13] added error --- lib/Service/UserService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 6a092113..c4b016d1 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -163,7 +163,7 @@ class UserService { if ($this->curl->getLastStatusCode() !== 200) { $this->logger->error('Error deleting mail folder of' . $email . '. Status Code: '.$this->curl->getLastStatusCode()); - throw new Exception('Error deleting mail folder of' . $email . '. Status Code: '.$this->curl->getLastStatusCode()); + throw new Exception(); } } public function sendWelcomeEmail(string $displayname, string $username, string $userEmail, string $language = 'en') : void { @@ -447,7 +447,7 @@ class UserService { $user = $this->getUser($uid); if (is_null($user)) { $this->logger->error("User with username '$uid' not found."); - throw new Exception("User with username '$uid' not found."); + throw new Exception(); } // Set the email address for the user $user->setEMailAddress($mailAddress); @@ -483,7 +483,7 @@ class UserService { return true; } $this->logger->error("Error checking if username '$username' is taken at common source, status code: " . (string) $statusCode); - throw new Exception("Error checking if username '$username' is taken at common source, status code: " . (string) $statusCode); + throw new Exception(); } public function addUsernameToCommonDataStore(string $username) : void { @@ -509,7 +509,7 @@ class UserService { if ($this->curl->getLastStatusCode() !== 200) { $this->logger->error("Error adding username '$username' to common data store."); - throw new Exception("Error adding username '$username' to common data store."); + throw new Exception(); } } } -- GitLab From 2184e3255aa11081aecbbcf8d128944a3022edaf Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 3 Apr 2024 00:54:24 -0700 Subject: [PATCH 11/13] added error --- lib/Service/UserService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index c4b016d1..a5d8ee2d 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -483,7 +483,7 @@ class UserService { return true; } $this->logger->error("Error checking if username '$username' is taken at common source, status code: " . (string) $statusCode); - throw new Exception(); + throw new Exception("Error checking if username '$username' is taken at common source, status code: " . (string) $statusCode); } public function addUsernameToCommonDataStore(string $username) : void { -- GitLab From 530daf3f9d26fa2e194f6cd4aaade41053476e6d Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 3 Apr 2024 01:39:58 -0700 Subject: [PATCH 12/13] Added exceptions --- lib/Controller/AccountController.php | 1 + lib/Service/UserService.php | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 412bda44..17d6e4c9 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -169,6 +169,7 @@ class AccountController extends Controller { $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]); $response->setStatus(500); } diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index a5d8ee2d..e7873d74 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -446,8 +446,7 @@ class UserService { public function setAccountDataLocally(string $uid, string $mailAddress, string $quota): void { $user = $this->getUser($uid); if (is_null($user)) { - $this->logger->error("User with username '$uid' not found."); - throw new Exception(); + throw new Exception("User with username '$uid' not found."); } // Set the email address for the user $user->setEMailAddress($mailAddress); @@ -482,7 +481,6 @@ class UserService { if ($statusCode === 200) { return true; } - $this->logger->error("Error checking if username '$username' is taken at common source, status code: " . (string) $statusCode); throw new Exception("Error checking if username '$username' is taken at common source, status code: " . (string) $statusCode); } @@ -508,8 +506,7 @@ class UserService { $this->curl->post($url, $params, $headers); if ($this->curl->getLastStatusCode() !== 200) { - $this->logger->error("Error adding username '$username' to common data store."); - throw new Exception(); + throw new Exception("Error adding username '$username' to common data store."); } } } -- GitLab From 22519b2cbc2ec8b9174c2e8cc1535d163e94df3a Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 3 Apr 2024 01:41:35 -0700 Subject: [PATCH 13/13] Added exceptions --- lib/Service/UserService.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index e7873d74..3cb2b910 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -162,8 +162,7 @@ class UserService { $this->curl->delete($url, $params, $headers); if ($this->curl->getLastStatusCode() !== 200) { - $this->logger->error('Error deleting mail folder of' . $email . '. Status Code: '.$this->curl->getLastStatusCode()); - throw new Exception(); + throw new Exception('Error deleting mail folder of' . $email . '. Status Code: '.$this->curl->getLastStatusCode()); } } public function sendWelcomeEmail(string $displayname, string $username, string $userEmail, string $language = 'en') : void { -- GitLab