Commit 8889a307 authored by i.vasilenko@iq-adv.ru's avatar i.vasilenko@iq-adv.ru
Browse files

Error codes

parent fb4a2b38
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -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
    {
+3 −3
Original line number Diff line number Diff line
@@ -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());
    }
+2 −0
Original line number Diff line number Diff line
@@ -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;
        }