Skip to content

Commit 282af57

Browse files
come-ncbackportbot[bot]
authored andcommitted
fix: Use HintException instead of InvalidArgumentException
To carry translated error messages intended for the end user, HintException is the correct class. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent b600bd3 commit 282af57

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

apps/provisioning_api/lib/Controller/VerificationController.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace OCA\Provisioning_API\Controller;
1111

12-
use InvalidArgumentException;
1312
use OC\Security\Crypto;
1413
use OCP\Accounts\IAccountManager;
1514
use OCP\AppFramework\Controller;
@@ -18,6 +17,7 @@
1817
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
1918
use OCP\AppFramework\Http\Attribute\OpenAPI;
2019
use OCP\AppFramework\Http\TemplateResponse;
20+
use OCP\HintException;
2121
use OCP\IL10N;
2222
use OCP\IRequest;
2323
use OCP\IUserManager;
@@ -69,13 +69,16 @@ public function showVerifyMail(string $token, string $userId, string $key): Temp
6969
try {
7070
if ($this->userSession->getUser()?->getUID() !== $userId) {
7171
// not a public page, hence getUser() must return an IUser
72-
throw new InvalidArgumentException($this->l10n->t('Logged in account is not mail address owner'));
72+
throw new HintException(
73+
'Logged in account is not mail address owner',
74+
$this->l10n->t('Logged in account is not mail address owner'),
75+
);
7376
}
7477
$email = $this->crypto->decrypt($key);
75-
} catch (\Exception $e) {
78+
} catch (HintException $e) {
7679
return new TemplateResponse(
7780
'core', 'error', [
78-
'errors' => [['error' => $e->getMessage()]]
81+
'errors' => [['error' => $e->getHint()]]
7982
], TemplateResponse::RENDER_AS_GUEST);
8083
}
8184

@@ -96,7 +99,10 @@ public function verifyMail(string $token, string $userId, string $key): Template
9699
$throttle = false;
97100
try {
98101
if ($this->userSession->getUser()?->getUID() !== $userId) {
99-
throw new InvalidArgumentException($this->l10n->t('Logged in account is not mail address owner'));
102+
throw new HintException(
103+
'Logged in account is not mail address owner',
104+
$this->l10n->t('Logged in account is not mail address owner'),
105+
);
100106
}
101107
$email = $this->crypto->decrypt($key);
102108
$ref = \substr(hash('sha256', $email), 0, 8);
@@ -109,7 +115,10 @@ public function verifyMail(string $token, string $userId, string $key): Template
109115
->getPropertyByValue($email);
110116

111117
if ($emailProperty === null) {
112-
throw new InvalidArgumentException($this->l10n->t('Email was already removed from account and cannot be confirmed anymore.'));
118+
throw new HintException(
119+
'Email was already removed from account and cannot be confirmed anymore.',
120+
$this->l10n->t('Email was already removed from account and cannot be confirmed anymore.'),
121+
);
113122
}
114123
$emailProperty->setLocallyVerified(IAccountManager::VERIFIED);
115124
$this->accountManager->updateAccount($userAccount);
@@ -121,8 +130,8 @@ public function verifyMail(string $token, string $userId, string $key): Template
121130
$throttle = true;
122131
$error = $this->l10n->t('Could not verify mail because the token is invalid.');
123132
}
124-
} catch (InvalidArgumentException $e) {
125-
$error = $e->getMessage();
133+
} catch (HintException $e) {
134+
$error = $e->getHint();
126135
} catch (\Exception $e) {
127136
$error = $this->l10n->t('An unexpected error occurred. Please contact your admin.');
128137
}

0 commit comments

Comments
 (0)