1
0
mirror of synced 2024-12-01 09:06:03 +03:00
service-bundle/Response/ErrorJsonResponseFactory.php

25 lines
658 B
PHP
Raw Normal View History

2021-02-05 14:47:54 +03:00
<?php
namespace RetailCrm\ServiceBundle\Response;
use RetailCrm\ServiceBundle\Models\Error;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\SerializerInterface;
class ErrorJsonResponseFactory
{
2022-07-20 14:38:42 +03:00
public function __construct(private SerializerInterface $serializer)
2021-02-05 14:47:54 +03:00
{
}
public function create(Error $error, int $statusCode = Response::HTTP_BAD_REQUEST, array $headers = []): Response
{
return JsonResponse::fromJsonString(
$this->serializer->serialize($error, 'json'),
$statusCode,
$headers
);
}
}