diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2022-04-04 12:30:02 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2022-04-04 12:30:02 +0300 |
commit | 27a4485ecd28618b93cafcebfd7859a51f476f04 (patch) | |
tree | 6548301b9f1e17269fb30b59a0856aec3ecdeb0c /lib/Controller | |
parent | 0b365745a9c478cdabef5a4836cb7a7cf3e10778 (diff) | |
parent | b39111631fff252b6fe2050cdb27de62e647d2c2 (diff) |
Merge remote-tracking branch 'origin/main' into chore/update-feature-outbox-III
Diffstat (limited to 'lib/Controller')
-rw-r--r-- | lib/Controller/AccountsController.php | 32 | ||||
-rw-r--r-- | lib/Controller/SieveController.php | 6 |
2 files changed, 24 insertions, 14 deletions
diff --git a/lib/Controller/AccountsController.php b/lib/Controller/AccountsController.php index e86c24f74..eb5c11d19 100644 --- a/lib/Controller/AccountsController.php +++ b/lib/Controller/AccountsController.php @@ -35,6 +35,7 @@ use OCA\Mail\Contracts\IMailManager; use OCA\Mail\Contracts\IMailTransmission; use OCA\Mail\Db\Mailbox; use OCA\Mail\Exception\ClientException; +use OCA\Mail\Exception\CouldNotConnectException; use OCA\Mail\Exception\ManyRecipientsException; use OCA\Mail\Exception\ServiceException; use OCA\Mail\Http\JsonResponse as MailJsonResponse; @@ -339,28 +340,37 @@ class AccountsController extends Controller { * @throws ClientException */ public function create(string $accountName, string $emailAddress, string $password = null, string $imapHost = null, int $imapPort = null, string $imapSslMode = null, string $imapUser = null, string $imapPassword = null, string $smtpHost = null, int $smtpPort = null, string $smtpSslMode = null, string $smtpUser = null, string $smtpPassword = null, bool $autoDetect = true): JSONResponse { - $account = null; - $errorMessage = null; try { if ($autoDetect) { $account = $this->setup->createNewAutoConfiguredAccount($accountName, $emailAddress, $password); } else { $account = $this->setup->createNewAccount($accountName, $emailAddress, $imapHost, $imapPort, $imapSslMode, $imapUser, $imapPassword, $smtpHost, $smtpPort, $smtpSslMode, $smtpUser, $smtpPassword, $this->currentUserId); } - } catch (Exception $ex) { - $errorMessage = $ex->getMessage(); + } catch (CouldNotConnectException $e) { + $this->logger->info('Creating account failed: ' . $e->getMessage(), [ + 'exception' => $e, + ]); + return \OCA\Mail\Http\JsonResponse::fail([ + 'error' => $e->getReason(), + 'service' => $e->getService(), + 'host' => $e->getHost(), + 'port' => $e->getPort(), + ]); + } catch (ServiceException $e) { + $this->logger->error('Creating account failed: ' . $e->getMessage(), [ + 'exception' => $e, + ]); + return \OCA\Mail\Http\JsonResponse::error('Could not create account'); } if (is_null($account)) { - if ($autoDetect) { - throw new ClientException($this->l10n->t('Auto detect failed. Please use manual mode.')); - } else { - $this->logger->error('Creating account failed: ' . $errorMessage); - throw new ClientException($this->l10n->t('Creating account failed: ') . $errorMessage); - } + return \OCA\Mail\Http\JsonResponse::fail([ + 'error' => 'AUTOCONFIG_FAILED', + 'message' => $this->l10n->t('Auto detect failed. Please use manual mode.'), + ]); } - return new JSONResponse($account, Http::STATUS_CREATED); + return \OCA\Mail\Http\JsonResponse::success($account, Http::STATUS_CREATED); } /** diff --git a/lib/Controller/SieveController.php b/lib/Controller/SieveController.php index 11fc5b186..ca1bfd4ce 100644 --- a/lib/Controller/SieveController.php +++ b/lib/Controller/SieveController.php @@ -179,7 +179,7 @@ class SieveController extends Controller { try { $this->sieveClientFactory->createClient($sieveHost, $sievePort, $sieveUser, $sievePassword, $sieveSslMode); } catch (ManagesieveException $e) { - throw CouldNotConnectException::create($e, 'ManageSieve', $sieveHost, $sievePort); + throw new CouldNotConnectException($e, 'ManageSieve', $sieveHost, $sievePort); } $mailAccount->setSieveEnabled(true); @@ -205,13 +205,13 @@ class SieveController extends Controller { $account = $this->accountService->find($this->currentUserId, $id); if (!$account->getMailAccount()->isSieveEnabled()) { - throw new CouldNotConnectException('ManageSieve is disabled.'); + throw new ClientException('ManageSieve is disabled.'); } try { $sieve = $this->sieveClientFactory->getClient($account); } catch (ManagesieveException $e) { - throw CouldNotConnectException::create($e, 'ManageSieve', $account->getMailAccount()->getSieveHost(), $account->getMailAccount()->getSievePort()); + throw new CouldNotConnectException($e, 'ManageSieve', $account->getMailAccount()->getSieveHost(), $account->getMailAccount()->getSievePort()); } return $sieve; |