From 1cbb9b13879b6d0cf920428e9859045e8a6b81e8 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 18 Sep 2023 05:29:35 -0700 Subject: [PATCH 1/8] removed a try catch from method --- lib/Service/UserService.php | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index a95bd408..57bdada0 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -163,9 +163,8 @@ class UserService { $toName = $user->getDisplayName(); $mainDomain = $this->getMainDomain(); - $email = $this->createSendGridEmail($fromEmail, $fromName, $toEmail, $toName, $templateID, $uid, $mainDomain); - try { + $email = $this->createSendGridEmail($fromEmail, $fromName, $toEmail, $toName, $templateID, $uid, $mainDomain); return $this->sendEmailWithSendGrid($email, $sendgridAPIkey); } catch (\Exception $e) { $this->logger->error($e, ['app' => Application::APP_ID]); @@ -197,20 +196,12 @@ class UserService { return $email; } private function sendEmailWithSendGrid(\SendGrid\Mail\Mail $email, string $sendgridAPIkey): bool { - try { - $sendgrid = new \SendGrid($sendgridAPIkey); - $response = $sendgrid->send($email); - - if ($response->statusCode() !== 200) { - throw new \Exception("SendGrid API error - Status Code: " . $response->statusCode()); - } - return true; - } catch (\Exception $e) { - $this->logger->error( - "Error while sending sendEmailWithSendGrid: " . $e->getMessage(), - ['app' => Application::APP_ID] - ); - return false; + $sendgrid = new \SendGrid($sendgridAPIkey); + $response = $sendgrid->send($email); + + if ($response->statusCode() !== 200) { + throw new \Exception("SendGrid API error - Status Code: " . $response->statusCode()); } + return true; } } -- GitLab From f6dc3d57ad71f21fc0e74c9cf7b928cad8f268d1 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 18 Sep 2023 05:32:26 -0700 Subject: [PATCH 2/8] replace logs instead exception --- lib/Service/UserService.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 57bdada0..b52cb968 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -200,7 +200,11 @@ class UserService { $response = $sendgrid->send($email); if ($response->statusCode() !== 200) { - throw new \Exception("SendGrid API error - Status Code: " . $response->statusCode()); + $this->logger->error( + "SendGrid API error - Status Code: " . $response->statusCode(), + ['app' => Application::APP_ID] + ); + return false; } return true; } -- GitLab From c5b4f7ab69a7ecad7400e269a2700099f555968c Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 18 Sep 2023 05:49:29 -0700 Subject: [PATCH 3/8] reverted --- lib/Service/UserService.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index b52cb968..388c5f90 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -195,17 +195,12 @@ class UserService { ]); return $email; } - private function sendEmailWithSendGrid(\SendGrid\Mail\Mail $email, string $sendgridAPIkey): bool { + private function sendEmailWithSendGrid(\SendGrid\Mail\Mail $email, string $sendgridAPIkey): void { $sendgrid = new \SendGrid($sendgridAPIkey); $response = $sendgrid->send($email); if ($response->statusCode() !== 200) { - $this->logger->error( - "SendGrid API error - Status Code: " . $response->statusCode(), - ['app' => Application::APP_ID] - ); - return false; + throw new \Exception("SendGrid API error - Status Code: " . $response->statusCode()); } - return true; } } -- GitLab From 0ac16b49d3c92cc5acb2e4ee48c0e21b18fb6bdc Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 18 Sep 2023 05:52:03 -0700 Subject: [PATCH 4/8] reverted --- 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 388c5f90..8d3325d4 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -165,8 +165,8 @@ class UserService { $mainDomain = $this->getMainDomain(); try { $email = $this->createSendGridEmail($fromEmail, $fromName, $toEmail, $toName, $templateID, $uid, $mainDomain); - return $this->sendEmailWithSendGrid($email, $sendgridAPIkey); - } catch (\Exception $e) { + $this->sendEmailWithSendGrid($email, $sendgridAPIkey); + } catch (\Throwable $e) { $this->logger->error($e, ['app' => Application::APP_ID]); return false; } -- GitLab From ce65bc20e46b98f78fa9d3bc2d3e2b26b3e850d6 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 18 Sep 2023 05:56:38 -0700 Subject: [PATCH 5/8] changes --- lib/Service/UserService.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 8d3325d4..fa2d5d18 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -6,13 +6,14 @@ namespace OCA\EcloudAccounts\Service; require __DIR__ . '/../../vendor/autoload.php'; +use \Psr\Log\LoggerInterface; use OCA\EcloudAccounts\AppInfo\Application; use OCP\Defaults; use OCP\IConfig; -use OCP\ILogger; use OCP\IUser; use OCP\IUserManager; use OCP\Util; +use Throwable; use UnexpectedValueException; @@ -28,9 +29,9 @@ class UserService { private $curl; private Defaults $defaults; - private ILogger $logger; + private LoggerInterface $logger; - public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, ILogger $logger, Defaults $defaults) { + public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, LoggerInterface $logger, Defaults $defaults) { $this->userManager = $userManager; $this->config = $config; $this->appConfig = $this->config->getSystemValue($appName); @@ -132,22 +133,22 @@ class UserService { return json_decode($answer, true); } catch (\Exception $e) { $this->logger->error('There has been an issue while contacting the external deletion script'); - $this->logger->logException($e, ['app' => Application::APP_ID]); + $this->logger->error($e, ['app' => Application::APP_ID]); } return null; } - public function sendWelcomeEmail(string $uid, string $toEmail) : bool { + public function sendWelcomeEmail(string $uid, string $toEmail) : void { $sendgridAPIkey = $this->getSendGridAPIKey(); if (empty($sendgridAPIkey)) { $this->logger->warning("sendgrid_api_key is missing or empty.", ['app' => Application::APP_ID]); - return false; + return; } $templateIDs = $this->getSendGridTemplateIDs(); if (empty($templateIDs)) { $this->logger->warning("welcome_sendgrid_template_ids is missing or empty.", ['app' => Application::APP_ID]); - return false; + return; } $language = $this->getUserLanguage($uid); @@ -166,9 +167,9 @@ class UserService { try { $email = $this->createSendGridEmail($fromEmail, $fromName, $toEmail, $toName, $templateID, $uid, $mainDomain); $this->sendEmailWithSendGrid($email, $sendgridAPIkey); - } catch (\Throwable $e) { + } catch (Throwable $e) { $this->logger->error($e, ['app' => Application::APP_ID]); - return false; + return; } } private function getSendGridAPIKey() : string { -- GitLab From 7531f4c0f8d0b7a92a88212ad870c7b10ee58c0c Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 18 Sep 2023 05:57:53 -0700 Subject: [PATCH 6/8] changes --- 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 fa2d5d18..56c83afb 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -169,8 +169,8 @@ class UserService { $this->sendEmailWithSendGrid($email, $sendgridAPIkey); } catch (Throwable $e) { $this->logger->error($e, ['app' => Application::APP_ID]); - return; } + return; } private function getSendGridAPIKey() : string { return $this->config->getSystemValue('sendgrid_api_key', ''); -- GitLab From cb44e1c5a7fadcc4524ef38d66e9cbf95e71cd16 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 18 Sep 2023 06:02:36 -0700 Subject: [PATCH 7/8] changes --- lib/Service/UserService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 56c83afb..7a8811e8 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -170,7 +170,6 @@ class UserService { } catch (Throwable $e) { $this->logger->error($e, ['app' => Application::APP_ID]); } - return; } private function getSendGridAPIKey() : string { return $this->config->getSystemValue('sendgrid_api_key', ''); -- GitLab From 28727213ce1281aa7ba77735ce1f81a6e3d5c5ae Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 18 Sep 2023 06:08:32 -0700 Subject: [PATCH 8/8] changes --- 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 7a8811e8..c1ccdc31 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -6,10 +6,10 @@ namespace OCA\EcloudAccounts\Service; require __DIR__ . '/../../vendor/autoload.php'; -use \Psr\Log\LoggerInterface; use OCA\EcloudAccounts\AppInfo\Application; use OCP\Defaults; use OCP\IConfig; +use OCP\ILogger; use OCP\IUser; use OCP\IUserManager; use OCP\Util; @@ -29,9 +29,9 @@ class UserService { private $curl; private Defaults $defaults; - private LoggerInterface $logger; + private ILogger $logger; - public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, LoggerInterface $logger, Defaults $defaults) { + public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, ILogger $logger, Defaults $defaults) { $this->userManager = $userManager; $this->config = $config; $this->appConfig = $this->config->getSystemValue($appName); @@ -133,7 +133,7 @@ class UserService { return json_decode($answer, true); } catch (\Exception $e) { $this->logger->error('There has been an issue while contacting the external deletion script'); - $this->logger->error($e, ['app' => Application::APP_ID]); + $this->logger->logException($e, ['app' => Application::APP_ID]); } return null; -- GitLab