Commit 6e776c2d authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

SYM-3 | Рефакторинг обработки ошибок

parent fc7a1db8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -8,6 +8,6 @@ class CategoryNotFoundException extends AppException
{
    public function __construct()
    {
        parent::__construct("Category not found", 404);
        parent::__construct("Category not found", ExceptionCode::CATEGORY_NOT_FOUND->value);
    }
}
+13 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace App\Exception;

enum ExceptionCode : int
{
    case VALIDATION_ERROR = 1;
    case REQUEST_BODY_CONVERT_ERROR = 2;
    case PRODUCT_NOT_FOUND = 3;
    case CATEGORY_NOT_FOUND = 4;
}
+17 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace App\Exception\HttpException;

use App\Exception\CategoryNotFoundException as NotFoundException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

class CategoryNotFoundException extends NotFoundException implements HttpExceptionInterface
{
    public function getResponse(): JsonResponse
    {
        return new JsonResponse($this->getMessage(), Response::HTTP_NOT_FOUND);
    }
}
+17 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace App\Exception\HttpException;

use App\Exception\AppException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

class HttpBadRequestException extends AppException implements HttpExceptionInterface
{
    public function getResponse(): JsonResponse
    {
        return new JsonResponse($this->getMessage(), Response::HTTP_BAD_REQUEST);
    }
}
+12 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace App\Exception\HttpException;

use Symfony\Component\HttpFoundation\JsonResponse;

interface HttpExceptionInterface
{
    public function getResponse(): JsonResponse;
}
Loading