diff --git a/app/src/Listeners/JwtListener.php b/app/src/Listeners/JwtListener.php index 07e56ad6037dc9d12d9177dd04e133d949cc8dd4..6e5e61f2640c846e006a0c1d4552dddcd80af790 100644 --- a/app/src/Listeners/JwtListener.php +++ b/app/src/Listeners/JwtListener.php @@ -44,16 +44,21 @@ class JwtListener /** * @param AuthenticationFailureEvent $event + * + * @throws JsonException */ public function onAuthenticationFailureResponse(AuthenticationFailureEvent $event): void { $response = new \App\Service\Response\Classes\Response(); $response->addError('Неверный email или пароль'); + $response->setStatusCode(Response::HTTP_UNAUTHORIZED); $event->setResponse($response->getResponse()); } /** * @param JWTInvalidEvent $event + * + * @throws JsonException */ public function onJWTInvalid(JWTInvalidEvent $event): void { @@ -66,18 +71,22 @@ class JwtListener /** * @param JWTNotFoundEvent $event + * + * @throws JsonException */ public function onJWTNotFound(JWTNotFoundEvent $event): void { $response = new \App\Service\Response\Classes\Response(); $response->addError('Отсутствует токен'); - $response->setStatusCode(Response::HTTP_FORBIDDEN); + $response->setStatusCode(Response::HTTP_UNAUTHORIZED); $event->setResponse($response->getResponse()); } /** * @param JWTExpiredEvent $event + * + * @throws JsonException */ public function onJWTExpired(JWTExpiredEvent $event): void { diff --git a/app/src/Listeners/KernelExceptionListener.php b/app/src/Listeners/KernelExceptionListener.php index a9ef3ccaf9ddbb5ca66d428ee6d4a6ce3a95c5ca..84f125c72c81c69ffb05e4eb5cc884a9cf37b888 100644 --- a/app/src/Listeners/KernelExceptionListener.php +++ b/app/src/Listeners/KernelExceptionListener.php @@ -8,17 +8,17 @@ use Symfony\Component\HttpKernel\KernelEvents; class KernelExceptionListener { - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ KernelEvents::EXCEPTION => 'onKernelException', ]; } - public function onKernelException(ExceptionEvent $event) + public function onKernelException(ExceptionEvent $event): void { $response = new \App\Service\Response\Classes\Response(); - $response->setStatusCode(Response::HTTP_FORBIDDEN); + $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR); $response->addError($event->getThrowable()->getMessage()); $event->setResponse($response->getResponse()); } diff --git a/app/src/Service/Action/UserBaseActionService.php b/app/src/Service/Action/UserBaseActionService.php index c6b201999fc70f1c267c0e5acc5ff63b0eadf4ab..0236fbcee9cd7b5847cf19e624a44d72e6497dac 100644 --- a/app/src/Service/Action/UserBaseActionService.php +++ b/app/src/Service/Action/UserBaseActionService.php @@ -4,6 +4,7 @@ namespace App\Service\Action; use App\Entity\User; use Symfony\Bundle\SecurityBundle\Security; +use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Service\Attribute\Required; abstract class UserBaseActionService extends BaseActionService @@ -23,6 +24,7 @@ abstract class UserBaseActionService extends BaseActionService public function customValidate(): bool { if ($this->user === null) { + $this->responseService->setStatusCode(Response::HTTP_UNAUTHORIZED); $this->responseService->addError('Вы не авторизованы'); return false; }