From 1b11cb98c5eb9fd22248aff2693251da7993293d Mon Sep 17 00:00:00 2001 From: "E.Alamo" Date: Wed, 15 May 2024 09:14:28 +0200 Subject: [PATCH] Improve exception thrown when user does not exists User not found is not a RuntimeException. It must be a NotFoundException --- src/User/Service/PasswordRecoveryService.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/User/Service/PasswordRecoveryService.php b/src/User/Service/PasswordRecoveryService.php index 0e5b597..a9e388a 100644 --- a/src/User/Service/PasswordRecoveryService.php +++ b/src/User/Service/PasswordRecoveryService.php @@ -19,6 +19,7 @@ use Da\User\Traits\MailAwareTrait; use Da\User\Traits\ModuleAwareTrait; use Exception; use Yii; +use yii\web\NotFoundHttpException; class PasswordRecoveryService implements ServiceInterface { @@ -50,7 +51,7 @@ class PasswordRecoveryService implements ServiceInterface $user = $this->query->whereEmail($this->email)->one(); if ($user === null) { - throw new \RuntimeException('User not found.'); + throw new NotFoundHttpException(Yii::t('usuario', 'User not found')); } $token = TokenFactory::makeRecoveryToken($user->id);