Improve exception thrown when user does not exists

User not found is not a RuntimeException. It must be a NotFoundException
This commit is contained in:
E.Alamo
2024-05-15 09:14:28 +02:00
committed by GitHub
parent c5a1e9b7c7
commit 1b11cb98c5

View File

@ -19,6 +19,7 @@ use Da\User\Traits\MailAwareTrait;
use Da\User\Traits\ModuleAwareTrait; use Da\User\Traits\ModuleAwareTrait;
use Exception; use Exception;
use Yii; use Yii;
use yii\web\NotFoundHttpException;
class PasswordRecoveryService implements ServiceInterface class PasswordRecoveryService implements ServiceInterface
{ {
@ -50,7 +51,7 @@ class PasswordRecoveryService implements ServiceInterface
$user = $this->query->whereEmail($this->email)->one(); $user = $this->query->whereEmail($this->email)->one();
if ($user === null) { if ($user === null) {
throw new \RuntimeException('User not found.'); throw new NotFoundHttpException(Yii::t('usuario', 'User not found'));
} }
$token = TokenFactory::makeRecoveryToken($user->id); $token = TokenFactory::makeRecoveryToken($user->id);