Skip to content

Commit a481519

Browse files
committed
fix: make the error message more specific
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 4e50c6c commit a481519

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

lib/Service/IdentifyMethod/SignatureMethod/EmailToken.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
namespace OCA\Libresign\Service\IdentifyMethod\SignatureMethod;
1010

1111
use OCA\Libresign\Exception\LibresignException;
12-
use OCA\Libresign\Helper\JSActions;
1312
use OCA\Libresign\Service\IdentifyMethod\IdentifyService;
1413
use OCA\Libresign\Vendor\Wobeto\EmailBlur\Blur;
1514

@@ -42,10 +41,15 @@ public function toArray(): array {
4241
};
4342

4443
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
45-
throw new LibresignException(json_encode([
46-
'action' => JSActions::ACTION_DO_NOTHING,
47-
'errors' => [['message' => $this->identifyService->getL10n()->t('Invalid email')]],
48-
]));
44+
$message = match ($entity->getIdentifierKey()) {
45+
// TRANSLATORS Error message shown when the email provided is not valid
46+
'email' => $this->identifyService->getL10n()->t('Invalid email'),
47+
// TRANSLATORS Error message shown when the signer has no valid email address in his profile, so he cannot be identified by email token
48+
'account' => $this->identifyService->getL10n()->t('Signer without valid email address to be identified by email token.'),
49+
// TRANSLATORS Error message shown when the email provided is not valid
50+
default => $this->identifyService->getL10n()->t('Invalid email'),
51+
};
52+
throw new LibresignException($message);
4953
}
5054

5155
$emailLowercase = strtolower($email);

tests/php/Unit/Service/IdentifyMethod/SignatureMethod/EmailTokenTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,14 @@ private function getClass(): EmailToken {
4242
}
4343

4444
#[DataProvider('providerToArrayWithInvalidEmail')]
45-
public function testToArrayWithInvalidEmail(mixed $email): void {
45+
public function testToArrayWithInvalidEmail(string $email): void {
4646
$instance = $this->getClass();
4747
$identifyMethod = new IdentifyMethod();
4848
$identifyMethod->fromRow([
4949
'identifierValue' => $email
5050
]);
5151
$instance->setEntity($identifyMethod);
5252
$this->expectException(LibresignException::class);
53-
$this->expectExceptionMessage(json_encode([
54-
'action' => 2000,
55-
'errors' => [['message' => 'Invalid email']],
56-
]));
5753
$instance->toArray();
5854
}
5955

0 commit comments

Comments
 (0)